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

    超级楼梯

    Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
    Total Submission(s) : 72   Accepted Submission(s) : 30

    Font: Times New Roman | Verdana | Georgia

    Font Size:

    Problem Description

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

    Input

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

    Output

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

    Sample Input

    2
    2
    3
    
    
    #include <iostream>
    #include <stdio.h>
    using namespace std;
    int main()
    {
        int m,n,i;
        int a[50];
        a[1]=1;
        a[2]=1;
        for(i=3;i<=40;i++)
            a[i]=a[i-1]+a[i-2];
        cin>>n;
        while(n--)
        {
            cin>>m;
            cout<<a[m]<<endl;
        }
        return 0;
    }

     

    Sample Output

    1
    2
  • 相关阅读:
    2020/5/18
    2020/5/17
    2020/5/15
    2020/5/13
    2020/5/12
    服务器环境配置五大免费主机系统
    6:运算符
    5:练习题
    4:Python的while循环
    3:Python条件语句
  • 原文地址:https://www.cnblogs.com/u013533289/p/4477317.html
Copyright © 2011-2022 走看看