嗯...
让一切从水开始吧...
水过初赛,但愿复赛能够接着水过...
这道题不记忆化会tle,所以用空间换时间,将每次的答案(只有20*20*20个)存下来,如果之前已经求过,就不需要重复求了....
AC代码:
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 5 using namespace std; 6 7 long long ans[25][25][25]; 8 9 inline long long w(long long a, long long b, long long c){ 10 if(a <= 0 || b <= 0 || c <= 0) return 1; 11 else if(ans[a][b][c]) return ans[a][b][c]; 12 else if(a > 20 || b > 20 || c > 20) ans[a][b][c] = w(20, 20, 20); 13 else 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); 14 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); 15 return ans[a][b][c]; 16 } 17 18 int main(){ 19 long long a, b, c; 20 while(~scanf("%lld%lld%lld", &a, &b, &c)){ 21 memset(ans, 0, sizeof(ans)); 22 if(a == -1 && b == -1 && c == -1) break; 23 printf("w(%lld, %lld, %lld) = ", a, b, c); 24 if(a > 20) a = 21; 25 if(b > 20) b = 21; 26 if(c > 20) c = 21; 27 printf("%lld ", w(a, b, c)); 28 } 29 return 0; 30 }