Problem Description:Since seeing the price of Apple on Christmas Eve, Lele has planted a row of apple trees at his doorstep, with a total of n trees. Suddenly Lele found a caterpillar on the P tree (starting from 1) on the left. In order to see the caterpillar become a butterfly process, Lele at the apple tree to observe for a long time. Although no butterflies were seen, Lele found a pattern: every minute, the caterpillar would randomly crawl from tree to tree adjacent to it. For example, in the first caterpillar in the 2nd tree, after a minute, the worm may be in the 1th tree or the 3rd tree, if the caterpillar in the beginning of a tree, a minute later, the caterpillar will be in the 2nd tree. Now tell you the number of apple trees N, as well as the beginning of the caterpillar position p, ask, in M minutes, after the caterpillar arrives at the T tree, there are altogether how many ways to walk the number of programs.
Enter Example 1:3 2 4 2
Output Example 1:4
Tip, the above 4 methods are as follows:
2->1->2->1->2
2->1->2->3->2
2->3->2->1->2
2->3->2->3- >2
The code is as follows:
/*
now tell you the number of apple trees N, as well as the beginning of the caterpillar position p, in M minutes, the caterpillar arrives at the T tree, total number of ways to walk
*/
#include <cstdio>
#include <cstring>
int Main () {
int n,p,m,t,i,j;
while (scanf ("%d%d%d%d", &n,&p,&m,&t)!=eof) {
int dp[110][110];
Memset (Dp,0,sizeof (DP));
Dp[0][p]=1;
for (i=1;i<=m;++i) //i minutes for
(J=1;J<=N;++J)//J Position
dp[i][j]=dp[i-1][j+1]+dp[i-1][j-1];// The total number of mobile schemes that represent the first minute to the J position is the sum of the mobile schemes on both sides of
printf ("%d\n", Dp[m][t]);
}
return 0;
}