[恢]hdu 2151
2011-12-21 11:19:32
地址:http://acm.hdu.edu.cn/showproblem.php?pid=2151
题意:中文。
mark:递推。dp[i][j]表示第i分钟在第j颗树上的走法。dp[i][j] = dp[i-1][j-1] + dp[i-1][j+1]。注意边界。
代码:
# include <stdio.h>
# include <string.h>
int dp[110][110] ;
int main ()
{
int n, p, m, t, i, j ;
while (~scanf ("%d%d%d%d", &n, &p, &m, &t))
{
memset (dp, 0, sizeof (dp)) ;
dp[0][p] = 1 ;
for (i = 1 ; i <= m ; i++)
{
for (j = 1 ; j < n ; j++)
dp[i][j] = dp[i-1][j-1] + dp[i-1][j+1] ;
dp[i][n] = dp[i-1][n-1] ;
}
printf ("%d\n", dp[m][t]) ;
}
return 0 ;
}