蒟蒻0分求助,样例全对,大佬请帮忙改一改

P1464 Function

ouiostream @ 2023-06-27 12:36:27

#include<bits/stdc++.h>
using namespace std;
long long h[50][50][50];
long long w(long long a,long long b,long long c){
    if(a<=0||b<=0||c<=0)return 1;   
    else if(a>20||b>20||c>20)return w(20,20,20);
    else if(h[a][b][c]!=0)return h[a][b][c];
    else if(a<b&&b<c)
        h[a][b][c]=w(a,b,c-1)+w(a,b-1,c-1)+w(a,b-1,c);
    else 
        h[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);
    return h[a][b][c];  
}
int main(){
    long long a,b,c;
    while(cin>>a>>b>>c){
        if(a==-1&&b==-1&&c==-1)
            break;
        cout<<"w("<< a <<", "<< b <<", "<< c << ") = ";
        cout<<w(a, b, c)<<endl;
    }
    return 0;
} 

by Loser_Syx @ 2023-06-27 12:46:38

@ouiostream

#include<bits/stdc++.h>
using namespace std;
long long h[50][50][50];
long long w(long long a,long long b,long long c){
    if(a<=0||b<=0||c<=0)return 1;   
    else if(a>20||b>20||c>20)return w(20,20,20);
    else if(h[a][b][c]!=0)return h[a][b][c];
    else if(a<b&&b<c)
        h[a][b][c]=w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c);// here
    else 
        h[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);
    return h[a][b][c];  
}
int main(){
    long long a,b,c;
    while(cin>>a>>b>>c){
        if(a==-1&&b==-1&&c==-1)
            break;
        cout<<"w("<< a <<", "<< b <<", "<< c << ") = ";
        cout<<w(a, b, c)<<endl;
    }
    return 0;
} 

by ouiostream @ 2023-06-27 12:59:24

@Saint_ying_xtf 谢大佬


|