Description
There is a cow, which has a small cow at the beginning of each year. Each heifer starts its fourth year with a heifer. Please program implementation how many cows are there in the first n years?
Input
The input data consists of multiple test instances, one for each test instance, including an integer n (0<n<55), and the meaning of n as described in the topic.
N=0 indicates the end of the input data and does not handle it.
Output
For each test instance, output the number of cows in the nth year.
Each output occupies one row.
Sample Input
2450
Sample Output
246
The puzzle: The Cattle (i>4) of the first year is equal to 3 years ago (because these cows will regenerate cows this year) + all cows last year. Dp[i] = dp[i-3]+dp[i-1];
Data is large, need to use a long long
#include <cstdio>#include<cstring>#include<iostream>#include<stdlib.h>#include<vector>#include<queue>#include<cmath>using namespacestd;#defineMAXN 100#defineOO 0x3f3f3f#definePI 3.1415926535897932intN;intK;Long LongDP[MAXN];voidinit () { for(intI=5; i<=maxn; i++) Dp[i]= dp[i-3] + dp[i-1];}intMain () {intt,m; while(SCANF ("%d",&m), m) {dp[1] =1; dp[2] =2; dp[3] =3; dp[4] =4; Init (); printf ("%i64d\n", Dp[m]); } return 0;}
A-the story of the cow