稻花香里说丰年,求助!!!~~(无助的蒟蒻)~~

P1464 Function

听取 WA 声一片(即答
by fengziyi @ 2023-02-23 19:15:56


你把输出格式读一遍就知道了
by C20220215 @ 2023-02-23 19:17:56


改了,20pts ``` #include<iostream> using namespace std; long long flag[50][50][50]; long long w(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){ if(flag[20][20][20] == -1){ flag[20][20][20] = w(20,20,20); } return flag[20][20][20]; }else if(a<b && b<c){ if(flag[a][b][c] == -1){ flag[a][b][c] = w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c); } }else{ if(flag[a][b][c] == -1){ flag[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 flag[a][b][c]; } int main(){ long long a,b,c; for(int i = 0;i<=20;i++){ for(int j = 0;j<=20;j++){ for(int k = 0;k<=20;k++){ flag[i][j][k] = -1; } } } scanf("%lld%lld%lld",&a,&b,&c); printf("w(%lld, %lld, %lld) = %lld\n",a,b,c,w(a,b,c)); while(a!=-1&&b!=-1&&c!=-1){ scanf("%lld%lld%lld",&a,&b,&c); if(a!=-1&&b!=-1&&c!=-1){ printf("w(%lld, %lld, %lld) = %lld\n",a,b,c,w(a,b,c)); } } return 0; } ``` 求dalao好人做到底
by _Coffice_ @ 2023-02-25 08:27:06


@[czw20110831](/user/868063) 感觉也不难这题,直接递推完事。 附上我的AC代码,你参考下。 ```cpp #include <bits/stdc++.h> using namespace std; #define f(i,a,b) for(int i=a;i<=b;i++) #define g(i,a,b) for(int i=a;i>=b;i--) long long w[21][21][21]; void init() { f(i,0,20) { f(j,0,20) { f(k,0,20) { if(i==0||j==0||k==0) w[i][j][k]=1; else { if(i<j&&j<k) w[i][j][k]=w[i][j][k-1]+w[i][j-1][k-1]-w[i][j-1][k]; else { w[i][j][k]=w[i-1][k][j]+w[i-1][j-1][k]+w[i-1][j][k-1]-w[i-1][j-1][k-1]; } } } } } } int main(){ int a,b,c,i=0; init(); while(~scanf("%d %d %d",&a,&b,&c)&&!(a==-1&&b==-1&&c==-1)) { if(a<0||b<0||c<0) printf("w(%d, %d, %d) = %lld\n",a,b,c,1); else { if(a>20||b>20||c>20) printf("w(%d, %d, %d) = %lld\n",a,b,c,w[20][20][20]); else { printf("w(%d, %d, %d) = %lld\n",a,b,c,w[a][b][c]); } } }; return 0; } ```
by mooktian @ 2023-02-25 20:12:02


Thanks♪(・ω・)ノ
by _Coffice_ @ 2023-02-26 08:47:38


|