问题描述
代码实现(C++)
底层原理:斐波那切数列
#include <iostream>
using namespace std
;
int stairNums(int n
) {
if (n
== 1) {
return 1;
}
if (n
== 2) {
return 2;
}
return stairNums(n
- 1) + stairNums(n
- 2);
}
int main() {
int n
;
cin
>> n
;
cout
<< stairNums(n
) << endl
;
return 0;
}
样例测试
转载请注明原文地址: https://lol.8miu.com/read-35317.html