描述
有一楼梯共m级,刚开始时你在第一级,若每次只能跨上一级或二级,要走上第m级,共有多少走法?
注:规定从一级到一级有0种走法。
- 输入
- 输入数据首先包含一个整数n(1<=n<=100),表示测试实例的个数,然后是n行数据,每行包含一个整数m,(1<=m<=40), 表示楼梯的级数。 输出
- 对于每个测试实例,请输出不同走法的数量。 样例输入
-
2 2 3
样例输出 -
1 2
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int ans[45],n,m;
int main(){
ans[1] = 0;
ans[2] = 1;
ans[3] = 2;
for(int i=4 ;i<=45 ;i++){
ans[i] = ans[i-1]+ans[i-2];
}
scanf("%d",&n);
while(n--){
scanf("%d",&m);
printf("%d\n",ans[m]);
}
return 0;
}