样例莓过,玄关求调QWQ

P1464 Function

lucy2012 @ 2024-04-07 19:55:36

#include<bits/stdc++.h>
using namespace std;
long long sum[30][30][30];
long long f(long a,long b,long c){
    if(a<=0||b<=0||c<=0) 
        return 1;
    else if(a>20||b>20||c>20)
        return f(20,20,20);
    else if(sum[a][b][c]!=0)
        return sum[a][b][c];
    else if(a<b&&b<c)
        sum[a][b][c]=f(a,b,c-1)+f(a,b-1,c-1)-f(a,b-1,c);
    else
        sum[a][b][c]=f(a-1,b,c)+f(a-1,b-1,c)+f(a-1,b,c-1)-f(a-1,b-1,c-1); 
}
int main(){
    long long a,b,c;
    while(cin>>a>>b>>c){
        if(a==-1&&b==-1&&c==-1)
            break;
        printf("w(%lld, %lld, %lld) = %lld\n",a,b,c,f(a,b,c));
    }
    return 0;
}

by Weekoder @ 2024-04-07 19:59:31

@lucy2012 f 函数的最后要返回 sum_{a,b,c} 哦。


by lucy2012 @ 2024-04-07 20:02:44

@Weekoder 额,非常感谢啦


|