以前做过类似的,USACO,2.3,开始数组开小了,导致数据乱了,然后超数据范围了,。。
1 #include <cstdio> 2 #include <iostream> 3 #include <cmath> 4 using namespace std; 5 #define LL __int64 6 LL dp[101][101][101]; 7 LL c[71][71]; 8 int main() 9 { 10 int i,j,n,k,u,h; 11 for(i = 0; i <= 70; i ++) 12 { 13 c[i][0] = 1; 14 } 15 for(i = 1; i <= 70; i ++) 16 { 17 for(j = 1; j <= 70; j ++) 18 c[i][j] = c[i-1][j-1] + c[i-1][j]; 19 } 20 dp[1][1][1] = 1; 21 scanf("%d%d",&n,&h); 22 for(i = 1; i < n; i ++) 23 { 24 for(j = 1; j <= n; j ++) 25 { 26 for(k = 1; k <= n; k ++) 27 { 28 if(dp[i][j][k] == 0) continue; 29 for(u = 1; u <= 2*k; u ++) 30 dp[i+1][j+u][u] += c[2*k][u]*dp[i][j][k]; 31 } 32 } 33 } 34 LL ans = 0; 35 for(i = h; i <= n; i ++) 36 { 37 for(k = 1; k <= n; k ++) 38 { 39 ans += dp[i][n][k]; 40 } 41 } 42 printf("%I64d ",ans); 43 return 0; 44 }