Climbing Stairs (DP)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.