蒟蒻0分全WA求调,玄关

P1464 Function

qhcKing @ 2024-08-04 16:50:38

#include <bits/stdc++.h> 
using namespace std;  
#define ll long long
ll rem[21][21][21];
bool vis[21][21][21];
ll w(ll a,ll b,ll c){
    if(a<=0||b<=0||c<=0) return 1;
    if(a>20||b>20||c>20) return w(20,20,20);
    if(vis[a][b][c]) return rem[a][b][c];
    if(a<b&&b<c) rem[a][b][c]=w(a,b,c-1)+w(a,b-1,c-1)+w(a,b-1,c);
    else rem[a][b][c]=w(a-1,b,c)+w(a-1,b-1,c)+w(a-1,b,c-1)-w(a-1,b-1,c-1);
    vis[a][b][c]=1;
    return rem[a][b][c];
}
int main(){  
    while(1){
        ll a,b,c;
        cin>>a>>b>>c;
        if(a==-1&&b==-1&&c==-1) break;
        cout<<"w("<<a<<", "<<b<<", "<<c<<')'<<" = "<<w(a,b,c)<<endl;
    }
    return 0;  
}

大佬求调


by Epi4any @ 2024-08-04 17:02:48

@qhcKing

#include <bits/stdc++.h> 
using namespace std;  
#define ll long long
ll rem[21][21][21];
bool vis[21][21][21];
ll w(ll a,ll b,ll c){
    if(a<=0||b<=0||c<=0) return 1;
    if(a>20||b>20||c>20) return w(20,20,20);
    if(vis[a][b][c]) return rem[a][b][c];
    if(a<b&&b<c) rem[a][b][c]=w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c);
    else rem[a][b][c]=w(a-1,b,c)+w(a-1,b-1,c)+w(a-1,b,c-1)-w(a-1,b-1,c-1);
    vis[a][b][c]=1;
    return rem[a][b][c];
}
int main(){  
    while(1){
        ll a,b,c;
        cin>>a>>b>>c;
        if(a==-1&&b==-1&&c==-1) break;
        cout<<"w("<<a<<", "<<b<<", "<<c<<')'<<" = "<<w(a,b,c)<<endl;
    }
    return 0;  
}

式子写错了。看了挺久。


by qhcKing @ 2024-08-04 17:23:37

@Faith_toChange

已AC,感谢大佬,已关


|