POJ3616:Milking Time
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 5682 | Accepted: 2372 |
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
题意:在各段时间之内产牛奶的数量不同,有休息时间,过了休息时间之后才能继续产牛奶。问总共能产多少牛奶。
代码:
#include <iostream>
#include <algorithm>
using namespace std; struct node{
int start;
int end;
int ef;
}eff[1005]; int dp[1000005];
bool cmp(struct node node1,struct node node2)
{
if(node1.start==node2.start)
return node1.end<node2.end;
else
return node1.start<node2.start;
} int main()
{
int N,M,R;
cin>>N>>M>>R; int i,j;
for(i=1;i<=M;i++)
{
cin>>eff[i].start>>eff[i].end>>eff[i].ef;
eff[i].end+=R;
}
sort(eff+1,eff+M+1,cmp); memset(dp,0,sizeof(dp)); for(i=1;i<=M;i++)
{
dp[eff[i].end]=eff[i].ef;
} int max_i;
for(i=1;i<=M;i++)
{
max_i=0;
for(j=1;j<i;j++)
{
if(eff[j].end<=eff[i].start)
{
if(dp[eff[j].end]>max_i)
{
max_i=dp[eff[j].end];
}
}
}
dp[eff[i].end]=max(max_i+eff[i].ef,dp[eff[i].end]);
}
max_i=0;
for(i=1;i<=M;i++)
{
if(dp[eff[i].end]>max_i)
{
max_i=dp[eff[i].end];
}
}
cout<<max_i<<endl; return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
POJ3616:Milking Time的更多相关文章
- POJ 2185 Milking Grid [二维KMP next数组]
传送门 直接转田神的了: Milking Grid Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 6665 Accept ...
- java web 开发三剑客 -------电子书
Internet,人们通常称为因特网,是当今世界上覆盖面最大和应用最广泛的网络.根据英语构词法,Internet是Inter + net,Inter-作为前缀在英语中表示“在一起,交互”,由此可知In ...
- 所有selenium相关的库
通过爬虫 获取 官方文档库 如果想获取 相应的库 修改对应配置即可 代码如下 from urllib.parse import urljoin import requests from lxml im ...
- Optimal Milking 分类: 图论 POJ 最短路 查找 2015-08-10 10:38 3人阅读 评论(0) 收藏
Optimal Milking Time Limit: 2000MS Memory Limit: 30000K Total Submissions: 13968 Accepted: 5044 Case ...
- POJ2112:Optimal Milking(Floyd+二分图多重匹配+二分)
Optimal Milking Time Limit: 2000MS Memory Limit: 30000K Total Submissions: 20262 Accepted: 7230 ...
- POJ3616 Milking Time —— DP
题目链接:http://poj.org/problem?id=3616 Milking Time Time Limit: 1000MS Memory Limit: 65536K Total Sub ...
- 题解报告:poj 2185 Milking Grid(二维kmp)
Description Every morning when they are milked, the Farmer John's cows form a rectangular grid that ...
- POJ3616 Milking Time【dp】
Description Bessie is such a hard-working cow. In fact, she is so focused on maximizing her producti ...
- 洛谷 P1204 [USACO1.2]挤牛奶Milking Cows Label:模拟Ex 74分待查
题目描述 三个农民每天清晨5点起床,然后去牛棚给3头牛挤奶.第一个农民在300秒(从5点开始计时)给他的牛挤奶,一直到1000秒.第二个农民在700秒开始,在 1200秒结束.第三个农民在1500秒开 ...
随机推荐
- 【PAT甲级】1006 Sign In and Sign Out (25 分)
题意: 给出学生人数M,输入M组学生ID,到机房的时间,离开机房的时间.输出最早到机房的学生的ID,空格,最后离开机房的学生的ID.(M大小未给出,就用了1e5) AAAAAccepted code: ...
- C++中的随机数
事情的开始是这样的,在大二的时候,写了几种排序算法,为了测试,就要为数组(或者容器)赋予一些随机初值,自然就用到了C/C++中的随机函数. 当时为了调用简单,将随机数赋值的过程写到了一个单独的函数里, ...
- ABC154F - Many Many Paths
梦回高中,定义的f(i,j)为从(0,0)到(i,j)一共有多少条路可以选择,易知我们要做i+j次选择,其中有i次是选择x轴,剩下的是y轴,所以f(i,j)=C(i+j,i)=C(i+j,j),给你一 ...
- mac下安装并启动RabbitMQ
前言 RabbitMQ是实现了高级消息队列协议(AMQP)的开源消息代理软件(亦称面向消息的中间件).RabbitMQ服务器是用Erlang语言编写的,而群集和故障转移是构建在开放电信平台框架上的 ...
- Guava LoadingCache不能缓存null值
测试的时候发现项目中的LoadingCache没有刷新,但是明明调用了refresh方法了.后来发现LoadingCache是不支持缓存null值的,如果load回调方法返回null,则在get的时候 ...
- 特约稿件 Java并发教程(Oracle官方资料)
本文是Oracle官方的Java并发相关的教程,感谢并发编程网的翻译和投递. (关注ITeye官微,随时随地查看最新开发资讯.技术文章.) 计算机的使用者一直以为他们的计算机可以同时做很多事情.他 ...
- Xcode 9.0 报错,Safe Area Layout Guide Before IOS 9.0
解决方案就是: 第一步 第二步 第三步 重新编译.
- zabbix server 安装部署
一:安装zabbix服务端 1.部署准备 命令:iptables -F #关闭防火墙命令:systemctl stop firewalld #关闭防火墙 设置解析,自建yum源 命令:c ...
- linux的ls -al指令
ls是“list”的意思,参数-al则表示列出所有的文件,包括隐藏文件,就是文件前面第一个字符为.的文件. 1.第一列便是这个文件的属性: #第一个属性表示这个文件时“目录.文件或链接文件等”: ...
- eclipse js文件无法保存错误
错误信息如下 Save Failedjdk.nashorn.internal.runtime.ECMAException.getEcmaError()Ljava/lang/Object; 网上多番查找 ...