HDU Dynamic Programming J

Source: Internet
Author: User

Problem Jtime limit:2000/1000ms (java/other) Memory limit:65536/32768k (Java/other) total submission (s): + Accept Ed Submission (s): 30Problem Description There is a total of a staircase of M-class, just at the beginning of you in the first level, if you can only step up one level or two at a time, to go to the grade m, how many kinds of methods?

Input data first contains an integer n, which represents the number of test instances, followed by n rows of data, each line containing an integer M (1<=m<=40), representing the series of stairs.

Output for each test instance, print out the number of different methods

Sample Input223

Sample Output12 Simple water question::
# include <iostream># include<cstdio># include<cstring># include<cmath># include<string># include<algorithm># include<vector>using namespacestd;intdp[1001];intMain () {intT; CIN>>T;  while(t--) {memset (DP,0,sizeof(DP)); intN; CIN>>N; dp[2] =1; dp[3] =2;  for(inti =4; I <= N; i++) {Dp[i]= Dp[i-1] + dp[i-2]; } cout<< Dp[n] <<Endl; }    return 0;}

HDU Dynamic Programming J

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.