S - the story of a cow HDU - 2018
Have a cow, it is born heifer beginning of each year. Each heifers from the fourth year, but also the beginning of a heifer born each year. Please programming in year n, when the total number of cows?
Input
A plurality of test input data examples, each test case per line, comprising an integer n (0 <n <55) , n the meanings as described in the title.
n = 0 indicates the end of input data, without processing.
Output
For each test case, the number of outputs of the n-th time in cows.
Each output per line.
Sample Input
2 4 5 0
Sample Output
2 4 6
Code Example:
#include<stdio.h>
#define N 55
int main(){
int n;
while(~scanf("%d",&n)&&n){
int a[N]={0};
for(int i=0;i<n;i++){
if(i<4) a[i]=i+1;
else a[i]=a[i-1]+a[i-3];
}
printf("%d\n",a[n-1]);
}
}
This problem will be simpler to use the number of columns, the number of columns of the usefulness of many, the future will open a special thematic point of view.