码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 2018 Cow Story DP

时间:2019-07-14 13:06:30      阅读:71      评论:0      收藏:0      [点我收藏+]

标签:als   int   sts   name   style   ever   beginning   tip   names   

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

标签:als   int   sts   name   style   ever   beginning   tip   names   

原文地址:https://www.cnblogs.com/CS-WLJ/p/11183769.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!