hdu1545 dp[i][x][y]表示到i位,从i到之前1比0最多多x个,0比1最多多y个(注意边界)
T^T老是把转移方程方向想错
1 #include<stdio.h> 2 #include<string.h> 3 long long dp[75][15][15]; 4 int main() 5 { 6 int n,k,i,j,x,y; 7 long long sum; 8 while (~scanf("%d%d",&n,&k)) 9 { 10 memset(dp,0,sizeof(dp)); 11 dp[1][1][0]=dp[1][0][1]=1; 12 for (i=2;i<=n;i++) 13 for (x=0;x<=k;x++) 14 for (y=0;y<=k;y++) 15 { 16 if (x==0&&y==0) continue; 17 if (x==0) dp[i][x][y]=dp[i-1][x][y-1]+dp[i-1][x+1][y-1]; 18 else if (y==0) dp[i][x][y]=dp[i-1][x-1][y]+dp[i-1][x-1][y+1]; 19 else dp[i][x][y]=dp[i-1][x-1][y+1]+dp[i-1][x+1][y-1]; 20 } 21 sum=0; 22 for (i=0;i<=k;i++) 23 for (j=0;j<=k;j++) 24 if (i!=0||j!=0) 25 sum+=dp[n][i][j]; 26 printf("%I64d\n",sum); 27 } 28 }