yiwugougou @ 2024-08-13 19:53:12
#include<bits/stdc++.h>
using namespace std;
int w(int a,int b,int c){
if(a<=0 || b<=0 || c<=0){
return 1;
}else if(a>20 || b>20 || c>20){
return w(20,20,20);
}else if(a<b && b<c){
return w(a,b,c-1) + w(a,b-1,c-1) - w(a,b-1,c);
}else{
return w(a−1,b,c) + w(a−1,b−1,c) + w(a−1,b,c−1) − w(a−1,b−1,c−1);
}
}
int main(){
int x,y,z;
while(cin>>x>>y>>z && (x!=-1 || y!=-1 || z!=-1)){
cout<<"w("<<x<<", "<<y<<", "<<z<<") = "<<w(x,y,z)<<endl;
}
return 0;
}
玄关
by goIdie @ 2024-08-13 19:56:38
@xiaohezi ,
#include<bits/stdc++.h>
#define int long long
using namespace std;
long long x,y,z,ans[155][155][155];
int w(int a,int b,int c)
{
if(a<=0||b<=0||c<=0)return 1;
if(a>20||b>20||c>20)return w(20,20,20);
if(ans[a][b][c])return ans[a][b][c];
if(a<b&&b<c)ans[a][b][c]=w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c);
else ans[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 ans[a][b][c];
}
signed main()
{
while(cin>>x>>y>>z)
{
if(x==-1&&y==-1&&z==-1)break;
cout<<"w("<<x<<", "<<y<<", "<<z<<") = "<<w(x,y,z)<<endl;
}
return 0;
}
by cj180202 @ 2024-08-13 19:57:50
@xiaohezi
会重复调用,浪费时间,记忆化答案。
by yiwugougou @ 2024-08-21 21:26:07
@cj180202
懂了,(最近有点忙,没来得及看)
by yiwugougou @ 2024-08-21 21:26:54
@goIdie 已关
@cj180202 已关
by yiwugougou @ 2024-08-21 21:35:42
@goIdie 按你的代码打了一遍,结果这样了
by goIdie @ 2024-08-21 21:37:18
@xiaohezi ,你那打的是减号吗。。。
by yiwugougou @ 2024-08-21 21:54:30
服了,图省事复制题目上的代码,结果他更我忘大家来找茬
by yiwugougou @ 2024-08-21 21:54:53
打错字了