超级楼梯

来源:互联网 发布:天猫魔盒自动删除软件 编辑:程序博客网 时间:2024/04/28 22:55

http://acm.hdu.edu.cn/diy/contest_showproblem.php?pid=1004&cid=22706




Problem Description

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

Input

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

Output

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

Sample Input

223

Sample Output

12

Author

lcy

Source

2005实验班短学期考试



#include <iostream>using namespace std;int main(){    int t,n;    cin>>t;    for(n=0; n<t; n++)    {        int i,j,a[100];        cin>>i;        a[2]=1;        a[3]=2;        for(j=4; j<=i; j++)            a[j]=a[j-1]+a[j-2];        cout<<a[i]<<endl;    }    return 0;}


0 0
原创粉丝点击