HDOJ 2151 Worm

http://acm.hdu.edu.cn/showproblem.php?pid=2151

 

 1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4 int cost_mat[102][102];
5 int N,P,M,T;
6 int main()
7 {
8 while(scanf("%d%d%d%d",&N,&P,&M,&T)!=EOF){
9 int i,j;
10 memset(cost_mat,0,sizeof(cost_mat));
11 cost_mat[0][P]=1;
12 for(i=1;i<=M;i++)
13 for(j=1;j<=N;j++){
14 if(j-1>=1)
15 cost_mat[i][j]+=cost_mat[i-1][j-1];
16 if(j+1<=N)
17 cost_mat[i][j]+=cost_mat[i-1][j+1];
18 }
19 printf("%d\n",cost_mat[M][T]);
20 }
21 }



posted @ 2011-11-29 20:32  linyvxiang  阅读(199)  评论(0编辑  收藏  举报