###Problem Description
有一超级楼梯,共无限级。刚开始时你在地面,你可以一步跨上第一级,也可以一步跨上第二级。
假设你每次只能向上跨一级或二级,那么你要走上第N级,共有多少种走法?
###Input
输入数据首先包含若干整数N(1<=N<=45),表示楼梯的级数。
###Output
对于每个测试实例N,请输出走到第N级楼梯的走法的数量。
###Sample Input
2
5
8
###Sample Output
2
8
34
###Sample Input
42
43
44
45
###Sample Output
433494437
701408733
1134903170
1836311903
#include <bits/stdc++.h>
using namespace std;
int count(int a){
int pre=1,now=2;
int kk=0;
for(int i=3;i<=a;i++){
kk=pre+now;
pre=now;
now=kk;
}
return kk;
}
int main(){
int a;
while(~scanf("%d",&a)){
if(a==0) cout<<"0"<<endl;
else if(a==1) cout<<"1"<<endl;
else if(a==2) cout<<"2"<<endl;
else {
int k=count(a);
cout<<k<<endl;
}
}
return 0;
}

被折叠的 条评论
为什么被折叠?



