HDU 2018 Cow Story DP

Posted cs-wlj

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU 2018 Cow Story DP相关的知识,希望对你有一定的参考价值。

Basic DP

Problem URL:https://vjudge.net/problem/HDU-2018

Describe:

There is a cow that gives birth to a heifer every year.Every heifer starts in the fourth year and also has a heifer at the beginning of each year.Please program how many cows are in the nth year?

Input:

The input data consists of multiple test instances, one for each test instance, including an integer n (0 < n < 55), the meaning of n as described in the title.n=0 means the end of the input data, no processing.

Sample Input:

2
4
5
0

Samle Output

2
4
6
DP[1] = 1
DP[2] = 2
DP[3] = 3
DP[4] = 4
DP[i] = DP[i-1] + DP[i-3]  i>=5

AC code :

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <bits/stdc++.h>
 4 using namespace std;
 5 int DP[55];
 6 int main()
 7 
 8     int  n;
 9     while(cin>>n && n!=0)
10     
11         DP[1] = 1;
12         DP[2] = 2;
13         DP[3] = 3;
14         DP[4] = 4;
15         for(int j = 5;j < 55;j++)
16             DP[j] = DP[j-1] + DP[j-3];
17         cout<<DP[n]<<endl;
18     
19     return 0;
20 
21    

 

以上是关于HDU 2018 Cow Story DP的主要内容,如果未能解决你的问题,请参考以下文章

hdu3966 Aragorn's Story

hdu 3966 Aragorn's Story

HDU 3966 Aragorn&#39;s Story(树链剖分)

AC日记——Aragorn's Story HDU 3966

HDU Aragorn's Story -树链剖分

HDU 3966 Aragorn's Story