1.知识点:递推
2.题意:有一对夫妇买了一头母牛,它从第2年起每年年初生一头小母牛。每头小母牛从第四个年头开始,每年年初也生一头小母牛。请编程实现在第n年的时候,共有多少头母牛?
3.递推关系方程:
if(x <= 4) a[x] = x;
else a[x] = a[x-1] + a[x-3];
代码:
#include <stdio.h>
int main()
{
int n, i;
long long a[60];
while(scanf("%d", &n) != EOF&&n)
{
a[1] = 1;
a[2] = 2;