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

    超级楼梯

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 59304    Accepted Submission(s): 30240

    Problem Description

    有一楼梯共M级,刚开始时你在第一级,若每次只能跨上一级或二级,要走上第M级,共有多少种走法?

    Input

    输入数据首先包含一个整数N,表示测试实例的个数,然后是N行数据,每行包含一个整数M(1<=M<=40),表示楼梯的级数。

    Output

    对于每个测试实例,请输出不同走法的数量

    Sample Input

    2

    2

    3

    Sample Output

    1

    2

    #include <cstdio>  
    #include <cmath>  
    int step[50];  
    int main()  
    {  
        int n,m;  
        scanf("%d",&n);  
        while(n--)  
        {  
            scanf("%d",&m);  
            step[1] = 1;  
            step[2] = 2;  
            for(int i=3; i<m; i++)  
            {  
                step[i] = step[i-1] + step[i-2];  
            }  
            printf("%d
    ",step[m-1]);  
        }  
        return 0;  
    }  
    

      

  • 相关阅读:
    cd的使用
    转换器模式
    装饰模式
    策略模式
    模板方法模式
    工厂模式
    类型信息
    proto编译组件使用
    proto编译引用外部包问题
    Kafka经典三大问:数据有序丢失重复
  • 原文地址:https://www.cnblogs.com/zhangliu/p/7063180.html
Copyright © 2011-2022 走看看