Zzz123456789101112 @ 2024-03-21 16:50:36
#include<iostream>
using namespace std;
int l[22][22][22]={0};//记忆化,将中间过程记忆化,可节省多余计算
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(l[a][b][c]!=0)return l[a][b][c];//先判断>20,后判断是否记忆化
if (a < b && b < c) l[a][b][c]= w(a, b, c - 1) + w(a, b - 1, c - 1) - w(a, b - 1, c);
else l[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 l[a][b][c];
}
int main() {
int a, b, c;
while (true) {
cin >> a >> b >> c;
if (a == -1 && b == -1 && c == -1)break;
printf("w(%d,%d,%d)=%d\n", a, b, c, w(a, b, c));
}
return 0;
}
by L_zaa_L @ 2024-03-21 16:59:18
@Zzz123456789101112 输出改成printf("w(%lld, %lld, %lld) = %lld\n", a, b, c, w(a, b, c));
by Zzz123456789101112 @ 2024-03-21 17:58:07
@zaa 只有第五个测试点过了
by Zzz123456789101112 @ 2024-03-21 18:01:39
@zaa 好啦好啦。没改longlong