HDU-2018雌牛の物語C/C++プッシュ


HDU-2018雌牛の物語
Problem Description
1頭の雌牛がいて、毎年年の初めに1頭の子牛を産んでいます.子牛は4年目から毎年年初にも子牛を産む.プログラミングして実現してn年目の時、何頭の雌牛がありますか?
Input
入力データは、整数n(0)を含む複数のテストインスタンスからなり、各テストインスタンスが1行を占める
Output
各試験例について、n年目の雌牛の数を出力した.出力ごとに1行を占めます.
Sample Input
2 4 5 0
Sample Output
2 4 6
My first passage on CSDN.The reason why I use English is that my tpewritting is so lame. But it might not be a bad thing for me to do this in English.
I attempts for times but all I got are WA! At first I use recursion(di gui) to solve the peoblem,but I gave up. Finally I searched it on the internet and knew all it need is just the recurision(di tui??)
(p.s Why digui and ditui use the same word in Eng??)
This is my code.
#include
int main()
{
	int cow[56],n;
	cow[0]=0;cow[1]=1;cow[2]=2;cow[3]=3;//         ,           
	for(int i=4;i<=55;i++){//   
			cow[i]=cow[i-1]+cow[i-3];
		}
	while(scanf("%d",&n)==1&&n){//          
		printf("%d
"
,cow[n]); } return 0; }