20pts求助

P1464 Function

Kinzo @ 2023-05-11 16:15:38

#include<bits/stdc++.h>
#define d long long
#define g(i) fixed<<setprecision(i)
using namespace std;

d x,y,z,p[25][25][25];

d w(d a,d b,d c) {
    if(a>20) a=21;
    if(b>20) b=21;
    if(c>20) c=21;
    if(a<=0||b<=0||c<=0) return 1;
    else if(p[a][b][c]!=0) return p[a][b][c];
    else if(a>20||b>20||c>20) p[a][b][c]=w(20,20,20);
    else if(a<b&&b<c) p[a][b][c]=w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c);
    else p[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 p[a][b][c];
}
int main() {
    while(x!=-1&&y!=-1&&z!=-1) {
        cin>>x>>y>>z;
        if(x!=-1&&y!=-1&&z!=-1) printf("w(%d, %d, %d) = %d\n",x,y,z,w(x,y,z));
    }
    return 0;
}

悬赏一个关注


by ao156 @ 2023-05-11 16:57:26

if(x!=-1&&y!=-1&&z!=-1) printf("w(%d, %d, %d) = %d\n",x,y,z,w(x,y,z));

数据类型开longlong,用lld输出。


|