4
5
想复杂了,可以无脑递归。
1 #include <bits/stdc++.h> 2 using namespace std; 3 int fun(int n) { 4 if (n == 1) { 5 return 1; 6 } 7 if (n == 2) { 8 return 2; 9 } 10 return fun(n - 1) + fun(n - 2); 11 } 12 int main() { 13 int n; 14 cin >> n; 15 cout << fun(n) << endl; 16 return 0; 17 }
原文:https://www.cnblogs.com/fx1998/p/12700045.html