求助!!!!

P1464 Function

zhutongxuan @ 2023-12-26 20:51:01

求解为何RE

#include<iostream>
#include<cstdio>
#include<cmath>
#define LL long long
using namespace std;

LL dp[20][20][20];

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(a < b && b < c){
        if(dp[a][b][c - 1] == 0){
            dp[a][b][c - 1] = w(a,b,c - 1);
        }
        if(dp[a][b - 1][c - 1] == 0){
            dp[a][b - 1][c - 1] = w(a,b - 1,c - 1);
        }
        if(dp[a][b - 1][c] == 0){
            dp[a][b - 1][c] = w(a,b - 1,c);
        }
        dp[a][b][c] = dp[a][b][c - 1] + dp[a][b - 1][c - 1] - dp[a][b - 1][c];
    }
    else{
        if(dp[a - 1][b][c] == 0){
            dp[a - 1][b][c] = w(a - 1,b,c);
        }
        if(dp[a - 1][b - 1][c] == 0){
            dp[a - 1][b - 1][c] = w(a - 1,b - 1,c);
        }
        if(dp[a - 1][b][c - 1] == 0){
            dp[a - 1][b][c - 1] = w(a - 1,b,c - 1);
        }
        if(dp[a - 1][b - 1][c - 1] == 0){
            dp[a - 1][b - 1][c - 1] = w(a - 1,b - 1,c - 1);
        }
        dp[a][b][c] = dp[a - 1][b][c] + dp[a - 1][b - 1][c] + dp[a - 1][b][c - 1] - dp[a - 1][b - 1][c - 1];
    }
    return dp[a][b][c];
}

int main(){
    LL a,b,c;
    while(scanf("%lld%lld%lld",&a,&b,&c)){
        if(a == -1 && b == -1 && c == -1){
            return 0;
        }
        printf("w(%lld, %lld, %lld) = ",a,b,c);
        printf("%lld\n",w(a,b,c));
    }
    return 0;
}

by fried_chicken @ 2023-12-26 20:55:38

数组开小了


by zhutongxuan @ 2023-12-26 20:57:19

@fried_chicken 谢大佬指教


by zhutongxuan @ 2023-12-26 20:58:22

终于过了!!弄了几十分钟!!


|