上台阶

    xiaoxiao2021-03-25  122

    上台阶

    题目描述

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

    注:规定从一级到一级有0种走法。

    输入

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

    样例输入

    2

    2

    3

    输出

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

    样例输出

    1

    2

    时间限制 C/C++语言:2000MS 其它语言:4000MS 内存限制 C/C++语言:65537KB 其它语言:589825KB #include<iostream> #include<cmath> #include <map> #include <algorithm> #include <iomanip> #include <cstring> #include <ctype.h> using namespace std; long long int b[40]; int main() {     b[0]=0;     b[1]=1;     for(int i=2; i<=40; i++)     {         b[i]=b[i-1]+b[i-2];     }    int n,a;    cin>>n;    while(n--)    {        cin>>a;        cout<<b[a]<<endl;    }    return 0; }
    转载请注明原文地址: https://ju.6miu.com/read-6484.html

    最新回复(0)