zoukankan      html  css  js  c++  java
  • 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    
  • 相关阅读:
    linux 进程操作脚本
    go 项目监听重启
    go 小题
    beego 基础
    beego 接口开发
    beego 安装
    mongo curd
    html的学习(一)
    ssl
    java编码的学习
  • 原文地址:https://www.cnblogs.com/CS-WLJ/p/11183769.html
Copyright © 2011-2022 走看看