J. Worm Time limit:1000 ms Case time limit:1000 ms Memory limit:32768kb 64-bit integer Io format:
% I64dJava class name:
Main SubmitStatusPID:
6295
Font Size: After seeing the price increase of apple on Christmas Eve, Lele planted a row of apple trees at the door of his house, N in total.
Suddenly Lele found a caterpillar on the P tree (counted from 1) from the left. Lele watched the apple tree for a long time to see the caterpillar change into a butterfly. Although no butterfly is seen, Lele finds a rule: every minute, the caterpillar will randomly climb from a tree to an adjacent tree.
For example, at the beginning, the caterpillar is located in 2nd trees. After one minute, the caterpillar may be located in 1st trees or 3rd trees. If at the beginning the caterpillar was on 1st trees, after one minute, the caterpillar would certainly be on 2nd trees.
I will tell you the number n of apple trees and the position P where Mao was at the beginning. How many walking solutions will the caterpillar reach the T tree in M minutes.
InputThis topic contains multiple groups of tests. Please process it until the end of the file (EOF ).
Each group of tests occupies one row, including four positive integers N, P, M, and T (for meanings, see the topic description, 0 <N, P, M, T <100)
OutputFor each group of data, the total number of solutions is output in one row.
Question data guarantee answer less than 10 ^ 9
Sample Input
3 2 4 23 2 3 2
Sample output
40HintThe first group of tests has the following four steps: 2-> 1-> 2-> 1-> 22-> 1-> 2-> 3-> 22-> 3-> 2-> 1-> 22-> 3 -> 2-> 3-> 2
Solution: This question is a simple dynamic programming question. You only need to find the dynamic equation.
Dynamic Equation: DP [I] [J] = DP [I-1] [J-1] + dp [I-1] [J + 1]; second IThe number of stamina for a caterpillar to climb to the J-tree is DP [I] [J], the value is the sum of the power of a caterpillar that climbed to the J-1 tree and the power of a caterpillar climbed to the J + 1 tree in the last second.
0th seconds. The number of stamina to climb to the P tree is 1, and the number of stamina to climb to other trees is 0. In other cases, it can be calculated based on the dynamically planned dynamic transfer equation. It took M seconds for the caterpillar to climb to the nth tree. The path strength is the value of DP [m] [T.
# Include <stdio. h> # include <string. h> int main () {int N, P, M, T; int DP [102] [102]; int I, J; while (scanf ("% d", & N, & P, & M, & T )! = EOF) {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]; printf ("% d \ n ", DP [m] [T]);} return 0 ;}