[USACO07NOV]挤奶的时间Milking Time
https://daniu.luogu.org/problemnew/show/2889
按右端点从小到大排序后DP
dp[i] 到第i个时间段的最大产奶量
不能按左端点排序,第i段由第j段更新时,第j段可能没挤奶,i,j都处于第k(k<j)段之后的休息时间
#include<cstdio>
#include<iostream>
#include<algorithm> using namespace std; #define N 1001 int dp[N]; struct node
{
int l,r,w;
}e[N]; void read(int &x)
{
x=; char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
} bool cmp(node p,node q)
{
return p.r<q.r;
} int main()
{
int n,m,R;
read(n); read(m); read(R);
for(int i=;i<=m;++i) read(e[i].l),read(e[i].r),read(e[i].w);
sort(e+,e+m+,cmp);
for(int i=;i<=m;++i)
{
dp[i]=max(dp[i-],e[i].w);
for(int j=;j<i;++j)
if(e[j].r+R<=e[i].l)
dp[i]=max(dp[j]+e[i].w,dp[i]);
}
cout<<dp[m];
}
题目描述
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.
奶牛Bessie在0~N时间段产奶。农夫约翰有M个时间段可以挤奶,时间段f,t内Bessie能挤到的牛奶量e。奶牛产奶后需要休息R小时才能继续下一次产奶,求Bessie最大的挤奶量。
输入输出格式
输入格式:
Line 1: Three space-separated integers: N, M, 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
输出格式:
- Line 1: The maximum number of gallons of milk that Bessie can product in the N hours
输入输出样例
[USACO07NOV]挤奶的时间Milking Time的更多相关文章
- P2889 [USACO07NOV]挤奶的时间Milking Time
P2889 [USACO07NOV]挤奶的时间Milking Time 奶牛Bessie在0~N时间段产奶.农夫约翰有M个时间段可以挤奶,时间段f,t内Bessie能挤到的牛奶量e.奶牛产奶后需要休息 ...
- bzoj1642 / P2889 [USACO07NOV]挤奶的时间Milking Time
P2889 [USACO07NOV]挤奶的时间Milking Time 普通的dp 休息时间R其实就是把结束时间后移R个单位而已.但是终点也需要后移R位到n+R. 每个时间段按起始时间排序,蓝后跑一遍 ...
- 【题解】Luogu P2889 [USACO07NOV]挤奶的时间Milking Time
Luogu P2889 [USACO07NOV]挤奶的时间Milking Time 题目描述 传送门Bessie is such a hard-working cow. In fact, she is ...
- 题解 最优的挤奶方案(Optimal Milking)
最优的挤奶方案(Optimal Milking) 时间限制: 1 Sec 内存限制: 128 MB 题目描述 农场主 John 将他的 K(1≤K≤30)个挤奶器运到牧场,在那里有 C(1≤C≤20 ...
- dp专题练习
顺便开另外一篇放一些学过的各种dp dp总结:https://www.cnblogs.com/henry-1202/p/9194066.html 开坑先放15道题,后面慢慢补 目标50道题啦~~,目前 ...
- Milking Cows 挤牛奶
1.2.1 Milking Cows 挤牛奶 Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 554 Solved: 108[Submit][Status ...
- 【POJ - 3616】Milking Time(动态规划)
Milking Time 直接翻译了 Descriptions 贝茜是一个勤劳的牛.事实上,她如此专注于最大化她的生产力,于是她决定安排下一个N(1≤N≤1,000,000)小时(方便地标记为0. ...
- USACO Section1.2 Milking Cows 解题报告
milk2解题报告 —— icedream61 博客园(转载请注明出处)---------------------------------------------------------------- ...
- poj 3616 Milking Time (基础dp)
题目链接 http://poj.org/problem?id=3616 题意:在一个农场里,在长度为N个时间可以挤奶,但只能挤M次,且每挤一次就要休息t分钟: 接下来给m组数据表示挤奶的时间与奶量求最 ...
随机推荐
- Daily target小队介绍(刘畅,陈杰,杨有存,唐祎琳,王晓哲,邵汝佳)
一.团队介绍 1.团队构成: 2.队名: Daily target,我们的口号是Target your day! 3.团队项目描述: 我们计划写一个用于老师发布任务,学生接受任务的安卓app.教师安排 ...
- 四则运算截图and代码
1.运行截图 2.代码 #include<stdio.h> #include<stdlib.h> int main() { int i=300; int a=0; while( ...
- 三公网络监督平台APP上线,源代码出售。
- url 地址含参数较多如何拼接
url 地址拼接是经常会遇到的问题.所以必须要掌握这个技术 1.合并参数对象,循环出来. var commonParams = { g_tk: 1928093487, inCharset: 'utf- ...
- python 菜鸟入门
python 菜鸟博客: http://www.cnblogs.com/wupeiqi/articles/5433893.html http://www.cnblogs.com/linhaifeng/ ...
- Windows 常用快捷方式
gpedit.msc-----组策略sndrec32-----录音机nslookup----- ip地址侦测器explorer------ 打开资源管理器logoff-------注销命令tsshut ...
- [转帖]华为Hi 1620 等ARM 服务器版本CPU信息.
华为ARM服务器恐依赖党政输血续命 一旦制裁立马休克 http://www.sohu.com/a/240833070_99934330 几年前,ARM服务器被业界炒的火热,AMD.高通.Marvell ...
- [转帖] Linux buffer 和 cache相关内容
Linux中Buffer/Cache清理 Lentil2018年9月6日 Linux中的buff/cache可以被手动释放,释放缓存的代码如下: https://lentil1016.cn/linux ...
- SpringBoot(八)_springboot集成swagger2
swagger是一个功能强大的api框架,它的集成非常简单,不仅提供了在线文档的查阅,而且还提供了在线文档的测试. (1) 引入依赖,我们选择现在最新的版本 <dependency> &l ...
- DBGrid添加行号编写笔记
procedure TForm1.ClientDataSet1NewRecord(DataSet: TDataSet); begin ShowMessage('你好'); ClientDataSet1 ...