全WA求助!

P1464 Function

f_hxr_ @ 2023-04-03 20:25:18

rt,改了好几遍都WA QAQ

#include<bits/stdc++.h>
using namespace std;
long long f[25][25][25],a,b,c;
long long w(long long x,long long y,long long z){
    if(x<=0||y<=0||z<=0)
        return 1;
    else if(x>20||y>20||z>20)
        return w(20,20,20);
    else if(f[x][y][z]!=-1)
        return f[x][y][z];
    else if(x<y&&y<z)
        return f[x][y][z]=w(x,y,z-1)+w(x,y-1,z-1)-w(x,y-1,z);
    else 
        return f[x][y][z]=w(x-1,y,z)+w(x-1,y-1,z)+w(x-1,y,z-1)-w(x-1,y-1,z-1);
}
int main(){
    memset(f,-1,sizeof(f));
    while(scanf("%lld%lld%lld",&a,&b,&c)==3){   
        if(a==-1&&b==-1&&c==-1)break;
        cout<<"w("<<a<<','<<b<<','<<c<<") = ";
        if(a>20)a=21;
        if(b>20)b=21;
        if(c>20)c=21;
        //cout<<a<<" "<<b<<" "<<c<<" "<<endl;
        cout<<w(a,b,c)<<endl;
    }
    return 0;
} 

by xiaoming007 @ 2023-04-03 20:27:54

@fhxr 缺了2个空格

#include<bits/stdc++.h>
using namespace std;
long long f[25][25][25],a,b,c;
long long w(long long x,long long y,long long z){
    if(x<=0||y<=0||z<=0)
        return 1;
    else if(x>20||y>20||z>20)
        return w(20,20,20);
    else if(f[x][y][z]!=-1)
        return f[x][y][z];
    else if(x<y&&y<z)
        return f[x][y][z]=w(x,y,z-1)+w(x,y-1,z-1)-w(x,y-1,z);
    else 
        return f[x][y][z]=w(x-1,y,z)+w(x-1,y-1,z)+w(x-1,y,z-1)-w(x-1,y-1,z-1);
}
int main(){
    memset(f,-1,sizeof(f));
    while(scanf("%lld%lld%lld",&a,&b,&c)==3){   
        if(a==-1&&b==-1&&c==-1)break;
        cout<<"w("<<a<<','<<' '<<b<<','<<' '<<c<<") = ";
        if(a>20)a=21;
        if(b>20)b=21;
        if(c>20)c=21;
        //cout<<a<<" "<<b<<" "<<c<<" "<<endl;
        cout<<w(a,b,c)<<endl;
    }
    return 0;
} 

by f_hxr_ @ 2023-04-03 20:30:04

@xiaoming007 已A,谢谢QWQ


|