Stair Climb time limit: 1 Sec Memory Limit: MB
Submit: 261 Solved: 137
[Submit] [Status] [Web Board] Description
When we were young, we all played the stair-climbing game: Two people scissors, won can climb the top, who first to the highest level wins. As college students, we should play a more level game.
Now a person to go to the N-level staircase, each step can choose the upper level or two levels, but not back. Find the number of scenarios for this n-level staircase.
Input
The first line has only one integer T (1<=t<=45), which represents the number of data groups.
Each line of the following T-line has an integer n (1<=n<=45) that indicates how many stairs there are.
Output
For each set of data output an integer s that represents the number of scenarios.
Sample Input
41234
Sample Output
1235
Code:
#include <cstdio> using namespace std; int dp[50]; int main () { dp[1]=1; dp[2]=2; for (int i=3;i<=46;i++) dp[i]=dp[i-1]+dp[i-2]; int t; scanf ("%d", &t); int n; while (t--) { scanf ("%d", &n); printf ("%d\n", Dp[n]); }
Climbing Stairs (DP)