Story of Hdu 2018 cows
Story of cowsTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission (s): 44955 Accepted Submission (s): 22309
Problem Description has a cow. It has a young cow every year. Starting from the fourth year, each calf also gave birth to a calf at the beginning of each year. How many cows are there during the nth year of programming?
The Input data is composed of multiple test instances. Each test instance occupies one row and contains an integer n (0 N = 0 indicates the end of the input data without processing.
For each test instance, Output outputs the number of cows in the nth year.
Each output occupies one row.
Sample Input
2450
Sample Output
246
According to the derivation, the number of cows in the nth year is equal to the number of cows in the previous year plus the number of cows in the nth n-3 year (the previous cows started to generate) n = n-1 + n-3
# Include
Using namespace std;
Int fun (int m)
{
If (m> 0 & m <5)
Return m;
Else
Return fun (m-1) + fun (m-3 );
}
Int main ()
{
Int n;
While (cin> n & n)
Cout < Return 0;
}