Super stair
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 10450 accepted submission (s): 5277
Problem description has a total of M-level stairs. At the beginning, you are at the first level. If you can only cross the upper level or Level 2 at a time, how many steps should you go to level M?
Input data first contains an integer N, indicating the number of test instances, followed by N rows of data, each row contains an integer m (1 <= m <= 40 ), the level of the stair.
Output for each test instance, please output the number of different steps
Sample Input
223
Sample output
12
CodeAs follows:
# Include <stdio. h> # include <stdlib. h> # include <math. h> # include <string. h> # include <time. h> int DP [45]; void Predeal () {/* memset (DP, 0, sizeof (DP); DP [0] = 1; for (INT I = 1; I <= 2; ++ I) for (Int J = I; j <= 40; ++ J) {DP [J] + = DP [J-I]; // printf ("DP [% d] = % d \ n", J, DP [J]);} */dp [1] = 1, DP [2] = 2; for (INT I = 3; I <= 40; ++ I) DP [I] = DP [I-1] + dp [I-2];} int main () {int t; Predeal (); scanf ("% d", & T ); while (t --) {int ask; scanf ("% d", & ask); printf ("% d \ n", DP [ask-1]);} return 0 ;}
during this period of time, because there were too many people in touch with backpacks, I first thought about the optimization of the motherboard function when I came back to this question, so I was confused by the mistake, there was no difference in coins in the original primary function, and 1 and 2 in this case were sorted in order. Xiaochen (a senior) came over and looked at it (with a smile). Isn't that a simple recursive question? F [I] = f [I-1] + F [I-2]; because each step can be one or two steps above.