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秒开 ...
随机推荐
- vue + element ui table表格二次封装 常用功能
因为在做后台管理项目的时候用到了大量的表格, 且功能大多相同,因此封装了一些常用的功能, 方便多次复用. 组件封装代码: <template> <el-table :data=&qu ...
- Linux centosVMware NFS介绍、NFS服务端安装配置、NFS配置选项
一.NFS介绍 NFS是Network File System的缩写 NFS最早由Sun公司开发,分2,3,4三个版本,2和3由Sun起草开发,4.0开始Netapp公司参与并主导开发,最新为4.1版 ...
- [原]JointJS流程图
最近项目上需要用流程图来做问题定界分析,之前有同事用jsPlumb做过,但是阅读代码后觉得比较麻烦,所以自己又找了一圈,找到一个叫Dagre-D3的开源类库,画出来的效果如下图,Dagre-D3最大的 ...
- 代码审计变成CTF
0x01 代码审计中的信息收集 一个cms代码量确实不少,通读代码耗时长,效果也不一定好.而一个功能点如果之前出过漏洞,特别是多次出现漏洞的地方,证明开发者对这个漏洞的理解不充分,很容易再次绕过补丁. ...
- php实现简单链式操作mysql数据库类
<?php $dbConfig = require_once(dirname(__FILE__).'/config.php'); class Db{ public $conn; ...
- JS array delete splice 区别
Delete in this case will only set the element as undefined: > myArray =['a','b','c','d'] >dele ...
- java并发初探ReentrantWriteReadLock
java并发初探ReentrantWriteReadLock ReenWriteReadLock类的优秀博客 ReentrantReadWriteLock读写锁详解 Java多线程系列--" ...
- Duilib自定义控件
新版博客已经搭建好了,有问题请访问 htt://www.crazydebug.com 在公司二期项目中为了将谷歌内核嵌入到duilib中,采用了自定义duilib控件的方法,由于也是第一次用duili ...
- Hadoop端口与界面
NameNode:7180 Cloudera Manager集群管理界面: NameNode:50070 NameNode Web UI/数据管理界面: NameNode:8020/9000 Ha ...
- Linux centosVMware shell脚本介绍、shell脚本结构和执行、date命令用法、shell脚本中的变量
一. shell脚本介绍 shell是一种脚本语言 aming_linux blog.lishiming.net 可以使用逻辑判断.循环等语法 可以自定义函数 shell是系统命令的集合 shell脚 ...