听取WA声一片,不解,求大佬解,必互关!

P1464 Function

zjrabc @ 2024-12-02 21:23:04

#include <bits/stdc++.h>
#define ll long long
using namespace std;
long long arr[30][30][30];
long long fun(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 fun(20,20,20);
    }
    if(arr[a][b][c]!=0){
        return arr[a][b][c];
    }
    if(a<b && b<c){
        return arr[a][b][c]=fun(a,b,c-1)+fun(a,b-1,c-1)+fun(a,b-1,c);
    }else{
        return arr[a][b][c]=fun(a-1,b,c)+fun(a-1,b-1,c)+fun(a-1,b,c-1)-fun(a-1,b-1,c-1);
    }
}
int main(){
    long long a,b,c;
    while(a!=-1 && b!=-1 && c!=-1){
        cin>>a>>b>>c;
        if(a==-1 && b==-1 && c==-1){
            return 0;
        }
        printf("w(%d, %d, %d) = %d\n",a,b,c,fun(a,b,c));
    }
    return 0;
}

by sdjjdjdjdjd @ 2024-12-02 21:36:47

应为

if(a<b && b<c) return arr[a][b][c]=fun(a,b,c-1)+fun(a,b-1,c-1)-fun(a,b-1,c);

把加号改成减号


by sdjjdjdjdjd @ 2024-12-02 21:38:46

还有,如果你开long long了,printf中也要写成%lld


by zjrabc @ 2024-12-03 11:25:23

@sdjjdjdjdjd 懂了大佬,已关!


|