超级楼梯

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

2
2
3

Sample Output

1
2

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;


}

原文地址:https://www.cnblogs.com/lengxia/p/4387878.html