POJ3616 Milking Time【dp】
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
思路:首先按照结束时间排序,dp[i]表示i时间挤奶的最大量,那么dp[i] = dp[i-1] + i时间挤奶量,仔细看代码推一推应该就会理解了。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=1000005;
const int M=1005;
int a[N],dp[N];
struct milk
{
	int start,end,value;
}s[M];
bool cmp(milk x,milk y)
{
	return x.end<y.end;
}
int main()
{
	int n,m,r;
	scanf("%d%d%d",&n,&m,&r);
	for(int i=1;i<=m;++i)
		scanf("%d%d%d",&s[i].start,&s[i].end,&s[i].value);
	sort(s+1,s+m+1,cmp);
	memset(dp,0,sizeof(dp));
	int maxn=0;
	for(int i=1;i<=m;++i)
	{
		for(int j=1;j<i;++j)
		{
			if(s[j].end+r<=s[i].start)
				dp[i]=max(dp[i],dp[j]);
		}
		dp[i]+=s[i].value;
		maxn=max(maxn,dp[i]);
	}
	printf("%d\n",maxn);
	return 0;
}												
											POJ3616 Milking Time【dp】的更多相关文章
- POJ 3616 Milking Time 【DP】
		
题意:奶牛Bessie在0~N时间段产奶.农夫约翰有M个时间段可以挤奶,时间段f,t内Bessie能挤到的牛奶量e.奶牛产奶后需要休息R小时才能继续下一次产奶,求Bessie最大的挤奶量.思路:一定是 ...
 - Kattis - honey【DP】
		
Kattis - honey[DP] 题意 有一只蜜蜂,在它的蜂房当中,蜂房是正六边形的,然后它要出去,但是它只能走N步,第N步的时候要回到起点,给出N, 求方案总数 思路 用DP 因为N == 14 ...
 - HDOJ 1423 Greatest Common Increasing Subsequence 【DP】【最长公共上升子序列】
		
HDOJ 1423 Greatest Common Increasing Subsequence [DP][最长公共上升子序列] Time Limit: 2000/1000 MS (Java/Othe ...
 - HDOJ 1501 Zipper 【DP】【DFS+剪枝】
		
HDOJ 1501 Zipper [DP][DFS+剪枝] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
 - HDOJ 1257 最少拦截系统 【DP】
		
HDOJ 1257 最少拦截系统 [DP] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
 - HDOJ 1159 Common Subsequence【DP】
		
HDOJ 1159 Common Subsequence[DP] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
 - HDOJ_1087_Super Jumping! Jumping! Jumping! 【DP】
		
HDOJ_1087_Super Jumping! Jumping! Jumping! [DP] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...
 - POJ_2533 Longest Ordered Subsequence【DP】【最长上升子序列】
		
POJ_2533 Longest Ordered Subsequence[DP][最长递增子序列] Longest Ordered Subsequence Time Limit: 2000MS Mem ...
 - HackerRank - common-child【DP】
		
HackerRank - common-child[DP] 题意 给出两串长度相等的字符串,找出他们的最长公共子序列e 思路 字符串版的LCS AC代码 #include <iostream&g ...
 
随机推荐
- 2015-2016 ACM-ICPC Pacific Northwest Regional Contest (Div. 2)  S Surf
			
SurfNow that you've come to Florida and taken up surng, you love it! Of course, you've realized that ...
 - hdu1814 Peaceful Commission——2-SAT
			
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1814 第一次的2-SAT,推荐博客:https://blog.csdn.net/jarjingx/arti ...
 - easyui图标对照
			
转自:https://blog.csdn.net/qq_34545192/article/details/78250816 原作者文章地址: http://www.cnblogs.com/timeme ...
 - Rails5 任务注释
			
任务注释 格式 # TODO: ... # FIXME: ... # OPTIMIZE ... 查看 rails notes 个别查看 rails notes:todo rail ...
 - [App Store Connect帮助]四、添加 App 图标、App 预览和屏幕快照(1)App Store 图标、App 预览和屏幕快照概述
			
您可以为您的 App Store 产品页提供有关您 App 的 App Store 图标.三个 App 预览和十张屏幕快照. App Store 图标 您必须提供一个 App Store 图标,用于在 ...
 - Linux 常规操作指南
			
1.修改Linux服务器别名 临时修改: vim /etc/hostname 修改别名 永久修改: vim /etc/sysconfig/network 添加 HOSTNAME=别名 重启服务器 ...
 - 有关lower_bound()函数的使用
			
lower_bound()函数需要加载头文件#include<algorithm>,其基本用途是查找有序区间中第一个大于或等于某给定值的元素的位置,其中排序规则可以通过二元关系来表示. 函 ...
 - 题解报告:hdu 1015 Safecracker
			
Problem Description === Op tech briefing, 2002/11/02 06:42 CST === "The item is locked in a Kl ...
 - List 的属性与方法整理
			
List<T> 类与 ArrayList 类比较类似.它实现了 IList<T> 泛型接口,长度可以动态增加. 可以使用 Add 或 AddRange 方法将项添加到 List ...
 - python批量删除文件夹
			
制作的python程序跑一次就占200多内存在temp下面,关键是还不释放,最开始都没有发现这个问题,知道自己的c盘越来越小才发现问题所在.所以就有了去删除temp下生成的文件 代码如下: impor ...