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 求 ...
随机推荐
- Understanding Java 8 Streams API---reference
http://java.amitph.com/2014/01/understanding-java-8-streams-api.html Since past few versions, Java h ...
- JavaScript资源分享
一. 资源教程: 综合类 前端知识体系 前端知识结构 Web前端开发大系概览 Web前端开发大系概览-中文版 Web Front-end Stack v2.2 En类资源汇总 免费的编程中文书籍索引 ...
- javascript 实现函数/方法重载效果
什么是重载? 在C#和JAVA等编程语言中函数重载是指在一个类中可以定义多个方法名相同但是方法参数和顺序不同的方法,以此来实现不同的功能和操作,这就是重载. JS没有重载,只能模拟重载 一般来说,如果 ...
- [LeetCode]21. Merge Two Sorted Lists合并两个有序链表
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing t ...
- Mysql数据库死锁分析相关概念
参考博客: mysql死锁问题分析(https://www.cnblogs.com/LBSer/p/5183300.html) mysql insert锁机制(http://yeshaoting.cn ...
- OLEDB存取BLOB型数据
现代数据库系统除了支持一些标准的通用数据类型以外,大多数还支持一种称之为BLOB型的数据. BLOB全称为big large object bytes, 大二进制对象类型,这种类型的数据通常用于存储文 ...
- 使用git版本管理工具
1.(1)正常提交:git add 提交文件 git init //git init之后建立一个.gitignore可以避免node_modules这类文件夹提交 git add . git co ...
- Android 时间范围选择器PickTimeDialog
个人提供了自己封装的第三方时间选择器,能够自定义时间格式,以及设置时间范围. 基础使用 PickTimeDialog pickDilog= new PickTimeDialog(this).setMa ...
- Linux 一直提示 login incorrect
- Azure 12 月新公布
Azure 12 月新发布:人脸识别 API 推出更新,媒体服务当前几种计量方式的调整,Azure Media Redactor 提供预览, Azure 密钥保管库开始计费, 和 Azure 支付方式 ...