After defeating the evil ghost, the general was ready to go back to the dormitory to tell everyone the news. I didn't expect the cup to happen again...
Do you know what kind of ghost is called "Lu Gui? The general is lost inexplicably. The general was going to go upstairs, but because of the ghost, he would not go up to the next floor or the next floor. This is random and he cannot control himself!
Assume that the general lives in the M building, and the general is in the K building at the beginning. Due to physical strength, the general can only go up or down the N th floor. Suppose there are 100 floors in the East 6 dormitory. Now I want to know how many ways the general can go back to the dormitory when his physical strength is exhausted.
For example, a general lives on the 5th floor. The general can go to or goes down the 5th floor. Now it is on the 1st floor,
The general will not be able to go back to the dormitory. Why? I don't know. Description has multiple groups of test data. Each group has one row of test data, which is the values of M, N, and K (0 <N <101 <M, K <). Separate them with spaces in the middle, the number of moves at the first layer and the number of moves at the first layer respectively. The Input corresponds to each group of test data, when the output is exhausted, the general just returned to the dormitory. The total number of steps Output44 5 415 5 1
Sample Input50
1 # include <stdio. h> 2 int x = 0; 3 void dfs (int m, int n, int step) 4 {5 if (step = m & n = 0) 6 {7 x ++; 8} 9 if (n = 0) 10 return; 11 if (step + 1 <101) 12 dfs (m, n-1, step + 1); 13 if (step-1> 0) 14 dfs (m, n-1, step-1); 15} 16 int main () 17 {18 int m, n, k; 19 x = 0; 20 while (scanf ("% d", & m, & n, & k )! = EOF) 21 {22 dfs (m, n, k); 23 printf ("% d \ n", x); 24 x = 0; 25} 26 return 0; 27}
View Code
Search practice swust oj 0324, general, Ghost, problem solving report