zhoujiatao @ 2023-10-28 09:34:38
代码:
#include<bits/stdc++.h>
using namespace std;
const int N=25;
const int M=1e6;
long long f[N][N][N];
long long w(int a,int b,int c)
{
if(a<=0||b<=0||c<=0)
return 1;
else if(f[a][b][c]!=0)
return f[a][b][c];
else if(a>20||b>20||c>20)
f[a][b][c]=w(20,20,20);
else if(a<b&&b<c)
f[a][b][c]=w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c);
else
f[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 f[a][b][c];
}
int main()
{
long long x,y,z;
while(1)
{
cin>>x>>y>>z;
if(x==-1&&y==-1&&z==-1)
break;
printf("w(%d,%d,%d) = ",x,y,z);
printf("%d",w(x,y,z));
cout<<endl;
}
return 0;
}
样例过来了但...
有大神看看改改谢谢
by Wyz110628 @ 2023-10-28 10:04:45
me too
#include<bits/stdc++.h>
using namespace std;
long long a[10001],b[10001],c[10001],k=1;
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(x<y && y<z)
{
return w(x,y,z-1)+w(x,y-1,z-1)-w(x,y-1,z);
}
else
{
return 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()
{
while(1)
{
cin>>a[k]>>b[k]>>c[k];
if(a[k]==-1 && b[k]==-1 && c[k]==-1)
{
break;
}
k++;
}
k--;
for(int i=1;i<=k;i++)
{
cout<<"w("<<a[i]<<","<<b[i]<<","<<c[i]<<") = "<<w(a[i],b[i],c[i])<<endl;
}
}
by zhouzihang3 @ 2023-10-28 10:09:29
#include<bits/stdc++.h>
using namespace std;
long long f[200][200][200];
#define main mian
long long dfs(long long a,long long b,long long c){
if(a<=0||b<=0||c<=0){
return 1;
}
if(a>20||b>20||c>20){
return 1048576;
}
if(f[a][b][c]!=0){
return f[a][b][c];
}
if(a<b&&b<c){
f[a][b][c]=dfs(a,b,c-1)+dfs(a,b-1,c-1)-dfs(a,b-1,c);
return f[a][b][c];
}
f[a][b][c]=dfs(a-1,b,c)+dfs(a-1,b-1,c)+dfs(a-1,b,c-1)-dfs(a-1,b-1,c-1);
return f[a][b][c];
}
int main(){
while(true){
long long a,b,c;
cin>>a>>b>>c;
if(a==b&&b==c&&c==-1){
break;
}
printf("w(%lld, %lld, %lld) = %lld\n",a,b,c,dfs(a,b,c));
}
return 0;
}
仅供参考,直接复制不得分