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秒开 ...
随机推荐
- 六、linux基础-计算机网络_线程_进程
6 计算机网络-线程和进程6.1 TCP/IP协议 TCP/IP是Unix/Linux世界的网络基础,在某种意义上,Unix网络就是Tcp/ip,而且Tcp/ip就是网络互连的标准他不是一个独立的协议 ...
- Servlet简单的登陆窗口
web.xml配置: jsp代码: 注意:action书写的是为这次登陆做处理类的别名,method就是请求的方式 Get请求方式没有请求实体 //如果只是看效果就光写一下service方法就行了 p ...
- Windows下ARP协议的工作原理简介
ARP协议(Address Resolve Protocol,地址解析协议)工作在TCP/IP协议的第二层-数据链路层,用于将IP地址转换为网络接口的硬件地址(媒体访问控制地址,即MAC地址). ...
- QQ企业通--客户端登陆模块设计---知识点2
Maximizable 属性 获取一个值,该值指定窗口是否可以最大化. fromBorderstyle 成员名称 说明 None 无边框. Fi ...
- Java Hashtable遍历与方法使用
参考文档 我参考了Java 集合系列11之 Hashtable详细介绍(源码解析)和使用示例,阅读了jdk 1.8的源码 Hashtable的继承关系 Hashtable继承了Dictionary类, ...
- [经验] Cocos Creator使用笔记 --- 调用不同脚本下的函数
因为 JavaScript 不同于 Java, 想要调用不同文件的函数的话不能直接 ClassName object = new ClassName(); object.function(param) ...
- R语言作图 绘制中国地图
参考:https://zhuanlan.zhihu.com/p/27360411 第一步.下载shapefile文件 一直都没有找到下载地址,死在了第一步 第二步.导入shp文件 第三步.画图
- Python Download Image (python + requests + BeautifulSoup)
环境准备 1 python + requests + BeautifulSoup 页面准备 主页面: http://www.netbian.com/dongman/ 图片伪地址: http://www ...
- 102、Java中String类之相等判断(忽略大小写)
01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...
- ThreadLocal的原理和在框架中的应用
ThreadLocal的原理和在框架中的应用 博客分类: java基础 框架多线程SpringthreadDAO 概述 我们知道Spring通过各种DAO模板类降低了开发者使用各种数据持久 ...