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秒开 ...
随机推荐
- 0-1背包问题(0-1 knapsack problem)
0-1背包问题描述:一个正在抢劫商店的小偷发现了n个商品,第i个商品价值 vi 美元,重 wi 磅,vi 和 wi 都是整数.这个小偷希望拿走价值尽量高的商品,但他的背包最多能容纳 S 磅重的商品,S ...
- NOIP2019 旅行
注意!注意!前方高能!本题卡常!!! 我们发现,所有的狗血剧情都在告诉我们,树的话直接dfs就出来了 那么基环树呢? 其实只要暴力删边,理论上的复杂度是可以过的qwq 但是删哪条边呢? 这里要引出一个 ...
- get your sqlserver database back by using EMC NW NMM
Dear all Yes ~ We can backup our sqlserver by EMC NW NMM. That is true and NW is a very very powerfu ...
- centos6.5安装图形操作界面
yum -y install xorg-x11-fonts-Type1 #安装Xwindow yum -y groupinstall "X Window System" #安装GN ...
- Py西游攻关之基础数据类型(六)-文件操作
Py西游攻关之基础数据类型 - Yuan先生 https://www.cnblogs.com/yuanchenqi/articles/5782764.html 九 文件操作 9.1 对文件操作流程 打 ...
- 本周总结(19年暑假)—— Part6
日期:2019.8.18 博客期:112 星期日
- 图形数据写入数据库,Filletream
图形数据写入数据库 用FileStream对象读模式打开图形文件 Dim 文件对象 As New FileStream(图形文件名, FileMode.Open, FileAccess.Read) 定 ...
- OPCDA通信--工作在透明模式下的CISCO ASA 5506-X防火墙配置
尊重原创,转发请声名 inside OPCSERVER 一台 outside OPCCLIENT 一台 route模式 配置没成功,放弃,采用透明模式 !----进入全局配置-- configure ...
- 代理实现aop以及代理工厂实现增强
一.静态代理实现 1.接口(抽象主题) 2.接口的实现类(真实主题) 3.代理类(代理主题) 4.测试类: ApplicationContext context=new ClassPathXmlApp ...
- 【剑指Offer面试编程题】题目1523:从上往下打印二叉树--九度OJ
题目描述: 从上往下打印出二叉树的每个节点,同层节点从左至右打印. 输入: 输入可能包含多个测试样例,输入以EOF结束. 对于每个测试案例,输入的第一行一个整数n(1<=n<=1000, ...