题目
有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少?
分析
兔子的规律为数列为1,1,2,3,5,8,13,21….
规律:第三个数永远等于前两个数之和。
不得不说名字是真可爱呀!
但没有我们coke老师可爱!
#include <bits/stdc++.h>
using namespace std;
int fun(int n) {
if (n == 0) return 0;
if (n == 1) return 1;
if (n >= 2)
return (fun(n-1) + fun(n-2));
}
int main()
{
int n;
cin>>n;
printf("%d\n", fun(n));
return 0;
}