algorithm_cmath @ 2024-09-28 21:20:12
#include<bits/stdc++.h>
using namespace std;
long long a,b,c;
long long r[25][25][25] = {};
long long w(long long i,long long j,long long k){
if (i <= 0 || j <= 0 || k <= 0) return 1;
if(i>20||j>20||k>20) return w(20,20,20);
else if(i<j&&j<k){
if(r[i][j][k-1] == 0) r[i][j][k-1] = w(i,j,k-1);
if(r[i][j-1][k-1] == 0) r[i][j-1][k-1] = w(i,j-1,k-1);
if(r[i][j-1][k] == 0) r[i][j-1][k] = w(i,j-1,k);
return r[i][j][k-1]+r[i][j-1][k-1]-r[i][j-1][k];
}else{
if(r[i-1][j][k] == 0) r[i-1][j][k] = w(i-1,j,k);
if(r[i-1][j-1][k] == 0) r[i-1][j-1][k] = w(i-1,j-1,k);
if(r[i-1][j][k-1] == 0) r[i-1][j][k-1] = w(i-1,j,k-1);
if(r[i-1][j-1][k-1] == 0) r[i-1][j-1][k-1] = w(i-1,j-1,k-1);
return r[i-1][j][k]+r[i-1][j-1][k]+r[i-1][j][k-1]-r[i-1][j-1][k-1];
}
}//w(1, 1, 1) = 2
//w(2, 2, 2) = 4
int main(){
cin>>a>>b>>c;
while (!(a==-1&&b==-1&&c==-1)){
if (a>20) a = 20;
if (b>20) b = 20;
if (c>20) c = 20;
cout<<"w("<<a<<", "<<b<<", "<<c<<") = "<<w(a,b,c)<<endl;
cin>>a>>b>>c;
}
return 0;
}
用了个不那么彻底的记忆化搜索和递归,r用来储存记忆化搜索,结果吗。。。自己看
(十分感谢大佬的指教)
by Didncan_yu @ 2024-09-28 21:26:47
@algorithm_cmath 不是,哥们,你主函数里把比20大的abc改了,后面还要输出abc的
by algorithm_cmath @ 2024-09-28 21:28:25
...哦,感谢! @Didncan_yu