总时间限制: 1000ms 内存限制: 65536kB描述
树老师爬楼梯,他可以每次走1级或者2级,输入楼梯的级数,求不同的走法数 例如:楼梯一共有3级,他可以每次都走一级,或者第一次走一级,第二次走两级 也可以第一次走两级,第二次走一级,一共3种方法。
输入输入包含若干行,每行包含一个正整数N,代表楼梯级数,1 <= N <= 30输出不同的走法数,每一行输入对应一行输出样例输入
5
8
10
样例输出
8
34
89
1 #include<iostream>
2 #include<cstdio>
3 #include<queue>
4 #include<cmath>
5 using namespace std;
6 int tot=0;
7 int find(int n)
8 {
9 if(n==1)return 1;
10 else if(n==2) return 2;
11 else return find(n-2)+find(n-1);
12 }
13 int main() {
14 int a,b;
15 while(cin>>a)
16 {
17 cout<<find(a)<<endl;
18 }
19 return 0;
20 }