Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
987 | 邓小龙 | 斐波那契数列(递归) | C++ | Wrong Answer | 1 MS | 264 KB | 652 | 2023-06-16 00:25:26 |
# include<iostream> using namespace std; int num(int m){ int r; if(m==1||m==2) r=1; //第一个月有1对,第二个月有1对 else r=num(m-1)+num(m-2);//第三个月开始num(m)=num(m-1)+num(m-2); return r; } int main(){ int n; cin>>n; for(int i =1;i<=n;i++){ cout<<i<<" "<<num(i)<<endl; } return 0; } /*典型的斐波那契数列 1 a 1 a 2 a b 3 a b c(a生) 5 a b c d(a生) e(b生) 8 a b c d e f(a生) g(b生) h(c生) 13 a b c d e f g h i(a) j(b) k(c) l(d) m(e) 21 规律: 兔子数量=上个月数量+上上个月数量 */
------Input------
25
------Answer-----
75025
------Your output-----
1 1 2 1 3 2 4 3 5 5 6 8 7 13 8 21 9 34 10 55 11 89 12 144 13 233 14 377 15 610 16 987 17 1597 18 2584 19 4181 20 6765 21 10946 22 17711 23 28657 24 46368 25 75025