题干:

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 Nhours

Sample Input

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

Sample Output

43

题目大意:

贝茜是一个勤劳的牛。事实上,她如此​​专注于最大化她的生产力,于是她决定安排下一个N(1≤N≤1,000,000)小时(方便地标记为0..N-1),以便她生产尽可能多的牛奶。

农民约翰有一个M(1≤M≤1,000)可能重叠的间隔列表,他可以在那里进行挤奶。每个区间我有一个起始小时(0≤starting_houri≤N),一个结束小时(starting_houri <ending_houri≤N),以及相应的效率(1≤efficiencyi≤1,000,000),表示他可以从中获取多少加仑的牛奶。贝西在那段时间。 Farmer John分别在开始时间和结束时间开始时开始和停止挤奶。在挤奶时,Bessie必须在整个间隔内挤奶。

尽管贝茜有其局限性。在任何间隔期间挤奶后,她必须休息R(1≤R≤N)小时才能再次开始挤奶。鉴于Farmer Johns的间隔清单,确定Bessie在N小时内可以产生的最大牛奶量。

一句话题意:

给奶牛挤奶,共m次可以挤,给出每次开始挤奶的时间st,结束挤奶的时间ed,还有挤奶的量ef,每次挤完奶要休息r时间,问最大挤奶量.

解题报告:

对于每一次挤奶,结束时间+=休息时间.

先把m次挤奶按照开始时间排个序,用f[i]表示挤完第i个时间段的奶以后的最大挤奶量,那么有:

f[i]=max(f[i],f[j]+(第i次挤奶.ef)) (1<=j<i&&(第j次挤奶).ed<=(第i次挤奶).st).

附上一年前写的垃圾代码Orz

这题一个点,一般这种题都是考虑贪心,从时间轴上去贪心,但是这题是dp,从第 i 个段 去考虑。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define F first
#define S second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
typedef struct Node{int start;int end;int value;
} node;
int dp[1005];
bool cmp (const node & a,const node & b) {return a.start<b.start;
}
int main()
{int n,m,r;node cow[1005];cin>>n>>m>>r;for(int i = 1 ; i<=m; i++) {scanf("%d%d%d",&cow[i].start,&cow[i].end,&cow[i].value);cow[i].end+=r;} sort(cow+1,cow+m+1,cmp);for(int i = 1 ; i<=m; i++) {dp[i]=cow[i].value;} for(int i = 1; i<=m; i++) {for(int j = 1; j<=i; j++) {if(cow[i].start>=cow[j].end) {dp[i]=max(dp[j]+cow[i].value,dp[i]);}}}printf("%d\n",*max_element(dp+1,dp+m+1));return 0 ;}
/*
12 4 2
1 2 8
10 12 19
3 6 24
7 10 31*/

【POJ - 3616】Milking Time (贪心+dp)相关推荐

  1. POJ 3616 Milking Time (字符串DP)

    题意:找元素关于对角线左或右对称的最大矩阵 思路:左右对角线只需要遍历一条就可以了.只要当前点往上遍历和往后遍历一样就可以. 1 #include<iostream> 2 #include ...

  2. POJ 3616 Milking Time

    解题思路: dp[i]:选择第i个区间获得最大值 1.只在第i个区间取奶 dp[i]=node[i].val; 2.如果能在前面已经取奶的后面接着取奶 node[j].ed+R<=node[i] ...

  3. 动态规划训练22 [Milking Time POJ - 3616 ]

    Milking Time POJ - 3616 说实话这道题目非常简单,本质上就是 多段有向图的求最大值问题.稍微变化的地方在于这个的的有向边没有那么明显 ,而是需要自己去寻找 如果任务i到任务j之间 ...

  4. URAL 1203 Scientific Conference(贪心 || DP)

    Scientific Conference 之前一直在刷计算几何,邀请赛连计算几何的毛都买见着,暑假这一段时间就做多校,补多校的题目,刷一下一直薄弱的DP.多校如果有计算几何一定要干掉-.- 题意:给 ...

  5. Codeforces Round #699 (Div. 2) E.Sorting Books(贪心+DP / 线段树)超高质量题解,看不懂来打我 ~

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 E - Sorting Books 一排书架上有 nnn 本书排成一排,每本书上有一个颜色 aia_i ...

  6. 【bzoj3174】[Tjoi2013]拯救小矮人 贪心+dp

    题目描述 一群小矮人掉进了一个很深的陷阱里,由于太矮爬不上来,于是他们决定搭一个人梯.即:一个小矮人站在另一小矮人的 肩膀上,知道最顶端的小矮人伸直胳膊可以碰到陷阱口.对于每一个小矮人,我们知道他从脚 ...

  7. J - Milking Time POJ - 3616(dp动态规划)

    Bessie is such a hard-working cow. In fact, she is so focused on maximizing her productivity that sh ...

  8. poj 3616(简单dp)

    题意:你有一头奶牛,你能够在一定的时间里挤奶.而且挤奶量也不同,每次挤奶要休息r时间,问你最大可以挤多少奶. 解题思路:这道题就是单调递增子序列的模型,dp[i]表示前i个任务可以得到的最优值.两层循 ...

  9. DP:Miking Time(POJ 3616)

    2015-09-21 奶牛挤奶 题目大意就是这只Bessie的牛产奶很勤奋,某农民有一个时刻表,在N时间内分成M个时间段,每个时间段Bessie会一直产奶,然后有一定的效益,并且Bessie产奶后要休 ...

最新文章

  1. Redmine+Apache+SVN+Postfix完整配置指南
  2. MPB:中科院城环所苏建强、朱永官等-功能基因高通量定量方法
  3. 将图片处理成圆形_如何把图片批量处理成指定/固定的文件大小/体积以内?
  4. 扫地机器人湿地_什么品牌的扫地机器人性价比最高?
  5. 15原型模式(Prototype)
  6. 隐秘的角落里数亿场AI战争正在发生
  7. Jmeter性能测试工具Timer定时器详解
  8. 6月全球Web服务器市场份额:Apache升至64.33%
  9. 今天用Map集合写了一个字符串字符统计的程序,看集合看的头痛,就看了一下GUI,于是就随便记点。
  10. 问题四十六:怎么用ray tracing画superellipsoid
  11. matlab7.0窗口教程,MATLAB7.0实用教程
  12. Linux网络编程-UDP实现QQ聊天功能
  13. 缓冲流(BufferedInputStream,BufferedOutputStream\BufferedReader,BufferedWriter)
  14. Webpack 5: The ‘compilation‘ argument must be an instance of Compilation
  15. 避坑:git在push本地文件到远程时,报错ailed to push some refs to https://xx/xx.git的解决办法
  16. java聚合函数_count()聚合函数正确用法
  17. html 如何去掉超链接下的下划线
  18. 怎样用文言文优雅地装逼!28万行唐诗中找出对称矩阵
  19. win10下搭建grpc 以及demo(idea maven java)
  20. 如何在中国制造网(made-in-china)上做生意

热门文章

  1. Sharepoint 2010 应用范围
  2. 调用Microsoft.Jet.OLEDB.4.0需要MDAC2.7支持
  3. Properties 类的使用
  4. project 模板_施工进度横道图不会做?18份计划模板收藏好,输入参数迅速成图...
  5. python注入点查找_sqlmap常用注入点检测爆破命令
  6. 626B. Cards
  7. 微软的平板电脑_Microsoft 微软 Surface Go 2 10.5英寸二合一平板电脑(m3-8100Y、8GB、128GB、LTE) 5788元...
  8. std::set作为一个有序集合
  9. bbb sdk6 ll_rw_block分析
  10. 解决SerMyAdmin无法登陆的问题