mairuisheng @ 2024-07-10 18:22:56
#include<bits/stdc++.h>
using namespace std;
long long ch[25][25][25];
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);
else if(a<b&&b<c)
{
if(ch[a][b][c]!=-1)return ch[a][b][c];
ch[a][b][c]=fun(a,b,c-1)+fun(a,b-1,c-1)+fun(a,b-1,c);
return ch[a][b][c];
}
else
{
if(ch[a][b][c]!=-1)return ch[a][b][c];
ch[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);
return ch[a][b][c];
}
}
int main()
{
long long a,b,c,ans;
memset(ch,-1,sizeof(ch));
while(1)
{
scanf("%lld %lld %lld",&a,&b,&c);
if(a==-1&&b==-1&&c==-1)return 0;
printf("w(%lld, %lld, %lld) = %lld\n",a,b,c,fun(a,b,c));
}
return 0;
}
测试结果:全WA
by a18981826590 @ 2024-07-10 18:25:22
@mairuisheng
#include<bits/stdc++.h>
using namespace std;
long long int a,b,c,d[25][25][25];
long long int w(long long int x,long long int y,long long int 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(x<y&&y<z){
if(!d[x][y][z-1]) d[x][y][z-1]=w(x,y,z-1);
if(!d[x][y-1][z-1]) d[x][y-1][z-1]=w(x,y-1,z-1);
if(!d[x][y-1][z]) d[x][y-1][z]=w(x,y-1,z);
return d[x][y][z-1]+d[x][y-1][z-1]-d[x][y-1][z];
}
else{
if(!d[x-1][y][z]) d[x-1][y][z]=w(x-1,y,z);
if(!d[x-1][y-1][z]) d[x-1][y-1][z]=w(x-1,y-1,z);
if(!d[x-1][y][z-1]) d[x-1][y][z-1]=w(x-1,y,z-1);
if(!d[x-1][y-1][z-1]) d[x-1][y-1][z-1]=w(x-1,y-1,z-1);
return d[x-1][y][z]+d[x-1][y-1][z]+d[x-1][y][z-1]-d[x-1][y-1][z-1];
}
}
int main(){
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 yx666 @ 2024-07-10 18:27:53
@mairuisheng
ch[a][b][c]=fun(a,b,c-1)+fun(a,b-1,c-1)-fun(a,b-1,c);
第二个 else-if 里面
by mairuisheng @ 2024-07-10 18:28:28
@a18981826590 能告诉我我错在哪里了吗?
by a18981826590 @ 2024-07-10 18:30:16
@mairuisheng
ch[a][b][c]=fun(a,b,c-1)+fun(a,b-1,c-1)+fun(a,b-1,c);
改为
ch[a][b][c]=fun(a,b,c-1)+fun(a,b-1,c-1)-fun(a,b-1,c);
+改为-
by mairuisheng @ 2024-07-10 18:33:19
@yx666 @a18981826590 谢谢两位大佬,问题已解决,已关。