题解 | #不死神兔问题#
不死神兔问题
https://www.nowcoder.com/practice/9fecec9c776c436b8a03ba0684ac76a7
#include <iostream> using namespace std; int getSum(int n); int main() { int n; cin >> n; cout << getSum(n) << endl; return 0; } // write your code here...... int getSum(int n) { if (n == 1 || n == 2) //n=1或2跳出递归 return 1; return getSum(n - 1) + getSum(n - 2); //返回前两个月相加 }