POJ 3616 Milking Time(加掩饰的LIS)
传送门:
http://poj.org/problem?id=3616
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 13406 | Accepted: 5655 |
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
挤奶工每次挤奶必须挤完完整的时间段,且每次挤完需要休息r时,求最终可获得的牛奶最大值
然后用动态规划做。
dp[i]代表第i个时间区间挤奶可获得的最大产奶量,
需要遍历前i-1个时间区间中结束时间小于等于第i个时间区间中开始时间,
求出最大值加上第i个时间区间的产奶量就是dp[i],
最后去dp数组最大值即可。
#include<stdio.h>
#include<algorithm>
#include<iostream>
using namespace std;
#define max_v 1005
struct node
{
int s,f,v;
}p[max_v];
bool cmp(node a,node b)
{
return a.f<b.f;
}
int dp[max_v];
int main()
{
/*
先按照贪心的想法按照结束时间(输入的结束时间+R)升序排序,
然后用动态规划做。
dp[i]代表第i个时间区间挤奶可获得的最大产奶量,
需要遍历前i-1个时间区间中结束时间小于等于第i个时间区间中开始时间,
求出最大值加上第i个时间区间的产奶量就是dp[i],
最后去dp数组最大值即可。
*/
int n,m,r;
while(cin>>n>>m>>r)
{
for(int i=;i<m;i++)
{
scanf("%d %d %d",&p[i].s,&p[i].f,&p[i].v);
p[i].f+=r;
}
sort(p,p+m,cmp);
for(int i=;i<max_v;i++)
dp[i]=;
dp[]=p[].v;
int ans=dp[];
for(int i=;i<m;i++)
{
int t=;
for(int j=;j<i;j++)
{
if(p[j].f<=p[i].s)
{
t=max(t,dp[j]);
}
}
dp[i]=t+p[i].v;
ans=max(ans,dp[i]);
}
printf("%d\n",ans);
}
return ;
}
POJ 3616 Milking Time(加掩饰的LIS)的更多相关文章
- POJ 3616 Milking Time (排序+dp)
题目链接:http://poj.org/problem?id=3616 有头牛产奶n小时(n<=1000000),但必须在m个时间段内取奶,给定每个时间段的起始时间和结束时间以及取奶质量 且两次 ...
- POJ 3616 Milking Time(最大递增子序列变形)
题目链接:http://poj.org/problem?id=3616 题目大意:给你时间N,还有M个区间每个区间a[i]都有开始时间.结束时间.生产效率(时间都不超过N),只能在给出的时间段内生产, ...
- poj 3616 Milking Time (基础dp)
题目链接 http://poj.org/problem?id=3616 题意:在一个农场里,在长度为N个时间可以挤奶,但只能挤M次,且每挤一次就要休息t分钟: 接下来给m组数据表示挤奶的时间与奶量求最 ...
- poj 3616 Milking Time
Milking ...
- poj 3616 Milking Time(dp)
Description Bessie ≤ N ≤ ,,) hours (conveniently labeled ..N-) so that she produces as much milk as ...
- POJ - 3616 Milking Time (动态规划)
Bessie is such a hard-working cow. In fact, she is so focused on maximizing her productivity that sh ...
- POJ 3616 Milking Time 简单DP
题意:奶牛Bessie在0~N时间段产奶.农夫约翰有M个时间段可以挤奶,时间段f,t内Bessie能挤到的牛奶量e.奶牛产奶后需要休息R小时才能继续下一次产奶,求Bessie最大的挤奶量. 详见代码 ...
- POJ 3616 Milking Time (字符串DP)
题意:找元素关于对角线左或右对称的最大矩阵 思路:左右对角线只需要遍历一条就可以了.只要当前点往上遍历和往后遍历一样就可以. #include<iostream> #include< ...
- poj 3616 Milking Time DP
题意:在给予的N个时间里,奶牛Bessie在M个时间段里进行产奶,但是每次产奶后都要休息R个时间 M个时间段里,分别有开始时间start和结束时间end,和该时间段里产奶的效率efficiency 求 ...
随机推荐
- 【ExtJS】自定义组件datetimefield(二)
接上[ExtJS]自定义组件datetimefield(一) 第三步:添加按钮事件绑定,获取选定的时间 privates:{ finishRenderChildren: function () { v ...
- java将list分为指定大小的新集合
上代码: import java.util.ArrayList; import java.util.List; public class JayCommonUtil { /** * 按指定大小,分隔集 ...
- 为数据赋能:腾讯TDSQL分布式金融级数据库前沿技术
欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 简介:李海翔,网名"那海蓝蓝",腾讯金融云数据库技术专家.中国人民大学信息学院工程硕士企业导师.著有<数据库事务处 ...
- Enjoy coding
Enjoy coding iTerm配置 主题选择 Solarized Dark LiquidCarbon 字体选择 Cousine for Powerline(需要安装Powerline字体库), ...
- PLC通信网络
PLC通信网络的分层 PLC通信网络大致可分为3层,管理层,单元层以及现场执行(AS-I)层.如下图所示. 在PLC通信网络的三层架构中,管理层,通信方式包括MPI,工业以太网(Profinet)以及 ...
- 移动端下滑刷新插件(jQuery插件)
由于在工作不能独自开发,而且为了给他们方便,自己写过不少的插件,不过今天刚好空闲,发出刚好完成的,移动端的下滑到底刷新插件.我不是很喜欢写插件给别人用,因为用起来自然是简单的,没什么难度,所以一起分享 ...
- unity3D使用C#遍历场景内所有元素进行操作
最近入门Unity3D,跟着教程做完了survival射击游戏,就想加一个功能,就是按一个按钮屏幕上的怪物都清空. 如图右下角所示. 我的方法是赋予所有怪物一个标签Tag,然后根据标签销毁Gameob ...
- javascript对HTML字符转义与反转义
1.背景:在项目中,经常遇到一些字符需要进行转义后才能显示到界面上,如“&”,在界面中显示的是“&”,在html中书写“&”,显示在界面的中的依然是“&”. 这时候,就 ...
- SELECT * FROM pet WHERE name REGEXP 'w';
To find names containing a “w”, use this query: SELECT * FROM pet WHERE name REGEXP 'w';
- #学习笔记#e2e学习使用(二)
前言: <#学习笔记#e2e学习使用(一)>主要记录了Vue项目的创建到e2e环境的搭建,以及期间遇到的各种问题和解决方法.本文建立在基础测试环境搭建完毕能正确运行的情况下,编写测试代码, ...