超级台阶

时间:2014-04-26 00:22:09   收藏:0   阅读:541

超级台阶

时间限制:1000 ms  |  内存限制:65535 KB
难度:3
 
描述

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

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

 
输入
输入数据首先包含一个整数n(1<=n<=100),表示测试实例的个数,然后是n行数据,每行包含一个整数m,(1<=m<=40), 表示楼梯的级数。
输出
对于每个测试实例,请输出不同走法的数量。
样例输入
2
2
3
样例输出
1
2

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

int main(int argc, char* argv[])
{
int n;
cin>>n;
while(n--)
{
int m,f[45],i;
cin>>m;
f[1]=0;f[2]=1;f[3]=2;
for(i=4;i<=40;i++)
f[i]=f[i-1]+f[i-2];
cout<<f[m]<<endl;
}
return 0;
}

超级台阶,布布扣,bubuko.com

原文:http://www.cnblogs.com/52Cyan/p/3690076.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!