zoukankan      html  css  js  c++  java
  • hdu 2041 超级楼梯

    Problem Description
    有一楼梯共M级,刚开始时你在第一级,若每次只能跨上一级或二级,要走上第M级,共有多少种走法?
     
    Input
    输入数据首先包含一个整数N,表示测试实例的个数,然后是N行数据,每行包含一个整数M(1<=M<=40),表示楼梯的级数。
     
    Output
    对于每个测试实例,请输出不同走法的数量
     
    Sample Input
    2 2 3
     
    Sample Output
    1 2
     
    Author
    lcy
     
    Source
     
    Recommend
    lcy   |   We have carefully selected several similar problems for you:  2044 2045 2046 2018 2050 
     
    到达第二层一种走法,到达第三层两种走法,那么到达第m(>3)层,要么从第m-1层走一步要么从m-2层跨两步。
    代码:
    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    #define inf 0x3f3f3f3f
    #define MAX 100000
    using namespace std;
    
    int n,m;
    
    int main() {
        scanf("%d",&n);
        int dp[40] = {0,1,1};
        for(int i = 3;i <= 40;i ++) {
            dp[i] = dp[i - 1] + dp[i - 2];
        }
        for(int i = 0;i < n;i ++) {
            scanf("%d",&m);
            printf("%d
    ",dp[m]);
        }
    }
  • 相关阅读:
    LeetCode#22 Generate Parentheses
    重传
    数学问题——gcdgcl
    数学问题——十进制转N进制
    数据模型
    IEEE
    格与代数系统
    数据字典
    贪心算法
    群论
  • 原文地址:https://www.cnblogs.com/8023spz/p/9748369.html
Copyright © 2011-2022 走看看