个人心得:一开始自己找状态,是这么理解的,只要前面一个满足就等于此时的值加上d(n-1),否则就是不挖此时的比较d(n-1)和

d(n-2)+cost,不过仔细一想忽略了很多问题,你无法确定n-2和此时的n是否可以一起挖,同时跳跃性的递归无法比较,

后面参考了网上的递推,他是确定这个n必须挖的最大值,则n前面的最大值+cost进行比较,仔细一想,这样是能求出挖这个

地方的最大值,所以后面输出就还要进行一轮最大值判断

 for(int i=;i<m;i++){
d[i]=C[i].earn;
for(int j=;j<i;j++)
{
if(C[j].ends<=C[i].start)
d[i]=max(d[i],d[j]+C[i].earn); }
}

注意了,它上面的代表着是D此时的值,即挖i的最大值,因为满足无后续性,所以内循环可以从0到i,确定是否挖与不挖。多想想

Language:
Default
Milking Time
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 10442   Accepted: 4378

Description

Bessie is such a hard-working cow. In fact, she is so focused on maximizing her productivity that she decides to schedule her next N (1 ≤ N ≤ 1,000,000) hours (conveniently labeled 0..N-1) so that she produces as much milk as possible.

Farmer John has a list of M (1 ≤ M ≤ 1,000) possibly overlapping intervals in which he is available for milking. Each interval i has a starting hour (0 ≤ starting_houri ≤ N), an ending hour (starting_houri < ending_houri ≤ N), and a corresponding efficiency (1 ≤ efficiencyi ≤ 1,000,000) which indicates how many gallons of milk that he can get out of Bessie in that interval. Farmer John starts and stops milking at the beginning of the starting hour and ending hour, respectively. When being milked, Bessie must be milked through an entire interval.

Even Bessie has her limitations, though. After being milked during any interval, she must rest R (1 ≤ R ≤ N) hours before she can start milking again. Given Farmer Johns list of intervals, determine the maximum amount of milk that Bessie can produce in the N hours.

Input

* Line 1: Three space-separated integers: NM, and R
* Lines 2..M+1: Line i+1 describes FJ's ith milking interval withthree space-separated integers: starting_houri , ending_houri , and efficiencyi

Output

* Line 1: The maximum number of gallons of milk that Bessie can product in the N hours

Sample Input

12 4 2
1 2 8
10 12 19
3 6 24
7 10 31

Sample Output

43
 #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<string>
#include<algorithm>
using namespace std;
struct cow
{
int start,ends;
int earn;
}C[];
int n,m,r;
bool cmp(cow a,cow b){
if(a.start==b.start)
return a.ends<b.ends;
return a.start<b.start;
}
int d[];
int main(){
cin>>n>>m>>r;
for(int i=;i<m;i++){
cin>>C[i].start>>C[i].ends>>C[i].earn;
C[i].ends+=r;
}
sort(C,C+m,cmp);
for(int i=;i<m;i++){
d[i]=C[i].earn;
for(int j=;j<i;j++)
{
if(C[j].ends<=C[i].start)
d[i]=max(d[i],d[j]+C[i].earn); }
}
int maxn=;
for(int i=;i<m;i++)
maxn=max(maxn,d[i]);
cout<<maxn<<endl;
return ;
}

Milking Time(DP)的更多相关文章

  1. poj 3616 Milking Time(dp)

    Description Bessie ≤ N ≤ ,,) hours (conveniently labeled ..N-) so that she produces as much milk as ...

  2. 【POJ】3616 Milking Time(dp)

    Milking Time Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10898   Accepted: 4591 Des ...

  3. LightOJ 1033 Generating Palindromes(dp)

    LightOJ 1033  Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...

  4. lightOJ 1047 Neighbor House (DP)

    lightOJ 1047   Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...

  5. UVA11125 - Arrange Some Marbles(dp)

    UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=sho ...

  6. 【POJ 3071】 Football(DP)

    [POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted ...

  7. 初探动态规划(DP)

    学习qzz的命名,来写一篇关于动态规划(dp)的入门博客. 动态规划应该算是一个入门oier的坑,动态规划的抽象即神奇之处,让很多萌新 萌比. 写这篇博客的目标,就是想要用一些容易理解的方式,讲解入门 ...

  8. Tour(dp)

    Tour(dp) 给定平面上n(n<=1000)个点的坐标(按照x递增的顺序),各点x坐标不同,且均为正整数.请设计一条路线,从最左边的点出发,走到最右边的点后再返回,要求除了最左点和最右点之外 ...

  9. 2017百度之星资格赛 1003:度度熊与邪恶大魔王(DP)

    .navbar-nav > li.active > a { background-image: none; background-color: #058; } .navbar-invers ...

随机推荐

  1. Android开发BUG及解决方法

    错误描述 问题1: 按照提示打开gradle-wrapper.properties文件 并且将gradle-2.8-all.zip改为gradle-2.10-all.zip,重新导入项目 问题2: 却 ...

  2. libhdfs的配置和使用

    测试环境:centos6.10,hadoop2.7.3,jdk1.8 测试代码:HDFSCSample.c #include "hdfs.h" #include <strin ...

  3. qnx 黑莓系统

    qnx 黑莓图形系统框架 http://www.360doc.com/content/07/0807/10/38907_658192.shtml http://blog.csdn.net/keyboa ...

  4. 登陆weblogic后页面控制台卡主

    输入http://localhost:7001/console进入控制页面,能登陆进去,但是登陆进去后页面就马上卡死,可以看到页面头部,其余都显示不出来. 重启后启动访问,能够正常进入,关闭weblo ...

  5. 继承Thread类与实现Runnable接口

    java中创建线程有两种方式: 1. 类继承Thread类,重写run方法,每创建一个实例对象即开启一个线程 2. 类实现Runnable接口,重写run方法,将实例对象传入新建Thread的方法: ...

  6. 20145231《Java程序设计》第三次实验报告

    实验三 敏捷开发与XP实现 实验内容 XP基础 XP核心实践 相关工具 实验要求 了解敏捷开发的基本方法以及XP软件开发的相关准则:了解代码编写的标准和原则:体会结对编程的好处: 实践体会版本控制的方 ...

  7. 深入理解JVM1

    1 Java技术与Java虚拟机 说起Java,人们首先想到的是Java编程语言,然而事实上,Java是一种技术,它由四方面组成: Java编程语言.Java类文件格式.Java虚拟机和Java应用程 ...

  8. INSPIRED启示录 读书笔记 - 第41章 产品经理的反省清单

    十大问题 1.产品能吸引目标消费者的关注吗? 2.产品的设计是否人性化,是否易于操作? 3.产品能在竞争中取胜吗?即使是面对未来风云变化的市场,依旧有取胜的把握吗? 4.我了解目标用户吗?产品(不是理 ...

  9. Introduction to vSphere Integrated Containers

    vSphere Integrated Containers enables IT teams to seamlessly run traditional workloads and container ...

  10. mongodb,redis简单学习

     2.mongodb安装配置简单学习                   配置好数据库路径就可以mongo命令执行交互操作了:先将服务器开起来:在开个cmd执行交互操作                 ...