[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组数据表示挤奶的时间与奶量求最 ...
随机推荐
- Head First Java & 异常
- Mongodb compass 介绍
参考官方文档:https://docs.mongodb.com/compass/current/install/#install-on-red-hat-enterprise-linux-rhel Mo ...
- LeetCode题解:(114) Flatten Binary Tree to Linked List
题目说明 Given a binary tree, flatten it to a linked list in-place. For example, Given 1 / \ 2 5 / \ \ 3 ...
- 第七周PSP&进度条
团队项目PSP 一.表格: C类型 C内容 S开始时间 E结束时间 I时间间隔 T净时间(mins) 预计花费时间(mins) 讨论 讨论beta阶段任务 10:00 12:30 28 270 ...
- try…catch 结构
try…catch 结构 一旦发生错误,程序就中止执行了.JavaScript 提供了try...catch结构,允许对错误进行处理,选择是否往下执行. try { throw new Error(' ...
- 【百度】大型网站的HTTPS实践(三)——HTTPS对性能的影响
HTTPS在保护用户隐私,防止流量劫持方面发挥着非常关键的作用,但与此同时,HTTPS也会降低用户访问速度,增加网站服务器的计算资源消耗.本文主要介绍HTTPS对性能的影响. HTTPS对访问速度的影 ...
- 计算机网络【3】—— IP地址分类与子网划分
一.IP地址分类
- [洛谷P4091][HEOI2016/TJOI2016]求和
题目大意:给你$n(n\leqslant10^5)$,求:$$\sum\limits_{i=0}^n\sum\limits_{j=0}^i\begin{Bmatrix}i\\j\end{Bmatrix ...
- BZOJ 3357: [Usaco2004]等差数列
3357: [Usaco2004]等差数列 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 338 Solved: 160[Submit][Statu ...
- 【BZOJ4006】【JLOI2015】管道连接
Description 传送门 Solution 题目要求相同颜色的点必须在一个连通块中,但会有多个颜色同属一个连通块使得解更优的情况. 想一想DP能否行得通:设\(g_i\)表示已考虑颜色状态为\( ...