小米oj #10 爬楼梯
描述
在你面前有一个n阶的楼梯,你一步只能上1阶或2阶。 请问计算出你可以采用多少种不同的方式爬完这个楼梯。
输入
一个正整数,表示这个楼梯一共有多少阶
输出
一个正整数,表示有多少种不同的方式爬完这个楼梯
输入样例
5
10
输出样例
8
89
简单的递归…
#include <bits/stdc++.h>
using namespace std;
int f(int n){
if(n == 1 || n == 0)
return 1;
else
return f(n-1) + f(n-2);
}
int main()
{
// please write your code here
int n;
while(cin >> n){
cout << f(n) << endl;
}
return 0;
}