lyc3090487933 @ 2024-11-07 09:35:49
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
ll i,j,k,nums[30][30][30] = {0}; //记忆初始化,记得都要用ll哦
ll w(ll a,ll b,ll c){
if(a<=0||b<=0||c<=0) return 1; //第一种情况
if(a>20||b>20||c>20) return w(20,20,20);//第二种
if(a<b&&b<c){//第三种
if(nums[a][b][c-1] == 0){//是否有记忆
nums[a][b][c-1] = w(a,b,c-1);
}
if(nums[a][b-1][c-1] == 0){
nums[a][b-1][c-1] = w(a,b-1,c-1);
}
if(nums[a][b-1][c] == 0){
nums[a][b-1][c] = w(a,b-1,c);
}
nums[a][b][c] = nums[a][b][c-1] + nums[a][b-1][c-1] - nums[a][b-1][c]; //返回
}
else{//其他情况
if(nums[a-1][b][c] == 0){
nums[a-1][b][c] = w(a-1,b,c);
}
if(nums[a-1][b-1][c] == 0){
nums[a-1][b-1][c] = w(a-1,b-1,c);
}
if(nums[a-1][b][c-1] == 0){
nums[a-1][b][c-1] = w(a-1,b,c-1);
}
if(nums[a-1][c-1][c-1] == 0){
nums[a-1][b-1][c-1] = w(a-1,b-1,c-1);
}
nums[a][b][c] = nums[a-1][b][c] + nums[a-1][b-1][c] + nums[a-1][b][c-1] - nums[a-1][b-1][c-1];
}
return nums[a][b][c];//结束
}
int main(){
while(1){
cin>>i>>j>>k;
if(i==-1&&j==-1&&k==-1) return 0;
cout<<"w("<<i<<", "<<j<<", "<<k<<')'<<" = "<<w(i,j,k)<<endl;
}
}
这是我改的
这是题解
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll; //手懒得打long long
ll a,b,c,note[30][30][30] = {0}; //记忆初始化,记得都要用ll哦
ll w(ll i,ll j,ll k){
if(i<=0||j<=0||k<=0) return 1; //第一种情况
if(i>20||j>20||k>20) return w(20,20,20);//第二种
if(i<j&&j<k){//第三种
if(note[i][j][k-1] == 0){//是否有记忆
note[i][j][k-1] = w(i,j,k-1);
}
if(note[i][j-1][k-1] == 0){
note[i][j-1][k-1] = w(i,j-1,k-1);
}
if(note[i][j-1][k] == 0){
note[i][j-1][k] = w(i,j-1,k);
}
note[i][j][k] = note[i][j][k-1] + note[i][j-1][k-1] - note[i][j-1][k]; //返回
}
else{//其他情况
if(note[i-1][j][k] == 0){
note[i-1][j][k] = w(i-1,j,k);
}
if(note[i-1][j-1][k] == 0){
note[i-1][j-1][k] = w(i-1,j-1,k);
}
if(note[i-1][j][k-1] == 0){
note[i-1][j][k-1] = w(i-1,j,k-1);
}
if(note[i-1][j-1][k-1] == 0){
note[i-1][j-1][k-1] = w(i-1,j-1,k-1);
}
note[i][j][k] = note[i-1][j][k] + note[i-1][j-1][k] + note[i-1][j][k-1] - note[i-1][j-1][k-1];
}
return note[i][j][k];//结束
}
int main(){
while(1){
cin>>a>>b>>c;
if(a==-1&&b==-1&&c==-1) return 0;
cout<<"w("<<a<<", "<<b<<", "<<c<<')'<<" = "<<w(a,b,c)<<endl;
}
}
by user100566 @ 2024-11-07 10:02:48
34 行
if(nums[a-1][c-1][c-1] == 0){
错了。
by user100566 @ 2024-11-07 10:04:27
@lyc3090487933 用文本编辑器替换变量名,然后 fc
查出来的
by Stugeon @ 2024-11-07 10:21:22
@user100566 我看了5遍都没找到问题,早知道用fc了
by lyc3090487933 @ 2024-11-07 16:51:22
@user100566 谢谢,给我看晕了都没找出来