【POJ】3616 Milking Time(dp)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 10898 | Accepted: 4591 | 
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: 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
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
Source
#include <cstdio>
#include <algorithm>
using namespace std;
int dp[];
struct c{
int begin,end,e;
}a[];
bool cmp(c a,c b)
{
if(a.begin<b.begin) return true;
if(a.begin==b.begin&&a.end<b.end) return true;
return false;
}
int main()
{
int n,m,r;
scanf("%d%d%d",&n,&m,&r);
for(int i=;i<=m;i++)
{
scanf("%d%d%d",&a[i].begin,&a[i].end,&a[i].e);
a[i].end+=r;// 实际的结束时间还需要加上休息时间
}
sort(a+,a++m,cmp);
for(int i=;i<=m;i++)
{
dp[i]=a[i].e;
for(int j=;j<=i;j++)
{
if(a[j].end<=a[i].begin)
dp[i]=max(dp[i],dp[j]+a[i].e);
}
}
printf("%d",*max_element(dp,dp++m));
return ;
}
【POJ】3616 Milking Time(dp)的更多相关文章
- 【POJ】2385 Apple Catching(dp)
		Apple Catching Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13447 Accepted: 6549 D ... 
- 【BZOJ】1068: [SCOI2007]压缩(dp)
		http://www.lydsy.com/JudgeOnline/problem.php?id=1068 发现如果只设一维的话无法转移 那么我们开第二维,发现对于前i个来说,如果确定了M在哪里,第i个 ... 
- poj 3616 Milking Time(dp)
		Description Bessie ≤ N ≤ ,,) hours (conveniently labeled ..N-) so that she produces as much milk as ... 
- 【POJ】2234 Matches Game(博弈论)
		http://poj.org/problem?id=2234 博弈论真是博大精深orz 首先我们仔细分析很容易分析出来,当只有一堆的时候,先手必胜:两堆并且相同的时候,先手必败,反之必胜. 根据博弈论 ... 
- 【51nod1519】拆方块[Codeforces](dp)
		题目传送门:1519 拆方块 首先,我们可以发现,如果第i堆方块被消除,只有三种情况: 1.第i-1堆方块全部被消除: 2.第i+1堆方块全部被消除:(因为两侧的方块能够保护这一堆方块在两侧不暴露) ... 
- 【bzoj1925】地精部落[SDOI2010](dp)
		题目传送门:1925: [Sdoi2010]地精部落 这道题,,,首先可以一眼看出他是要我们求由1~n的排列组成,并且抖来抖去的序列的方案数.然后再看一眼数据范围,,,似乎是O(n^2)的dp?然后各 ... 
- 【ZOJ2278】Fight for Food(dp)
		BUPT2017 wintertraining(16) #4 F ZOJ - 2278 题意 给定一个10*10以内的地图,和p(P<=30000)只老鼠,给定其出现位置和时间T(T<=1 ... 
- 【vijos】1764 Dual Matrices(dp)
		https://vijos.org/p/1764 自从心态好了很多后,做题的确很轻松. 这种题直接考虑我当前拿了一个,剩余空间最大能拿多少即可. 显然我们枚举每一个点拿出一个矩形(这个点作为右下角), ... 
- 【Luogu】P3856公共子串(DP)
		题目链接 DP.设last[i][j]是第i个串字符'j'所在的最后的位置,f[i][j][k]是第一个串匹配到i,第二个串匹配到j,第三个串匹配到k,最多的公共子串数. 那么我们三重循环i.j.k, ... 
随机推荐
- echarts-detail---散点图
			data4 = [{ xAxis: result.AvgEvaluate, seriesId: ', name: '基干360综合分' }, { yAxis: evalue, seriesId: ', ... 
- Android敏捷开发、CI(持续集成)探究
			比较老的几篇文章,依旧有学习价值 http://blog.csdn.net/baodinglaolang/article/details/9530695 http://blog.csdn.net/ba ... 
- WIP - Study Perf (by quqi99)
			版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本版权声明 (http://blog.csdn.net/quqi99) Perf Flame Graph sudo perf ... 
- Ubuntu循环登录libGL error: fbConfigs swrast等
			Ubuntu16.04更新NVIDIA驱动后,无法进入桌面,使用vim .xsession-errors 查看错误信息,如下: libGL error: No matching fbConfigs o ... 
- iOS TUN之避免UDP包ip分片
			iOS的NetworkExtension给应用暴露了一个虚拟网卡TUN设备,可以设置其MTU值.如果上层应用发送的IP包大于这个MTU就会被分片.(详见:http://blog.csdn.net/n5 ... 
- Win10安装Ubuntu16.04 双系统
			Tips: 双系统Ubuntu可以使用机器的GPU硬件,虚拟机不可以 压缩卷留的空间尽量大一点,不要相信50G够用 选UEFI,并关闭 Secure Boot,不要选 Legacy 选UEFI,就要在 ... 
- 密钥库文件格式[keystore]代码
			密钥库文件格式[keystore]代码 格式 : JKS 扩展名 : .jks/.ks 描述 : [Java Keystore]密钥库的Java实现版本,pro ... 
- Postfix邮件黑名单和白名单
			本文主要介绍如何用Postfix添加域名黑名单和白名单,用以处理垃圾邮件. 1.修改postfix主配置文件,增加限制语句 vim /etc/postfix/main.cf # 文末添加一行,限制往本 ... 
- [剑指offer]数组中最小的K个数,C++实现
			原创博文,转载请注明出处! http://github.com/wanglei5205 http://cnblogs.com/wanglei5205 # 题目 输入n个整数,找出其中最小的K个数.例如 ... 
- SpringDataJpa增删改查
			资料来源网址:http://www.cnblogs.com/hawell/p/SpringDataJpa.html Repository(几个常用的例子) @Repository public int ... 
