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 ...
随机推荐
- beego4---web项目结构
app.conf appname = blog1 httpport = runmode = dev controllersmy package controllersmy //跟外面的包名一致 imp ...
- centos7 tengine2.1.2 编译安装 防火墙设置
安装 pcre 和 openssl yum -y install pcre pcre-devel yum -y install openssl openssl-devel wget http://te ...
- Android 通过USB查看kernel调试信息【转】
本文转载自:http://blog.csdn.net/lindonghai/article/details/51683644 前提:电脑已安装adb并可正常使用. 在调试Android驱动时,需要查看 ...
- SIM卡APDU指令【转】
本文转载自:http://blog.csdn.net/hlx156/article/details/54136756 一个APDU可以是一个命令,也可以是命令的响应. 命令APDU的一般格式: CLA ...
- A Go library implementing an FST (finite state transducer)——mark下
https://github.com/couchbaselabs/vellum Building an FST To build an FST, create a new builder using ...
- [JSOI 2016] 灯塔
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=4850 [算法] 首先对不等式进行移项 : hj <= hi + p - sqr ...
- 第九周 Leetcode 502. IPO (HARD)
Leetcode 502 一个公司 目前有资产W 可以选择实现K个项目,每个项目要求公司当前有一定的资产,且每个项目可以使公司的总资产增加一个非负数. 项目数50000 设计一个优先队列,对于当前状态 ...
- JEECG框架使用Tomcat启动报ClassNotFound
JEECG框架缺少一个类,名为AnnotationProcessor,包名为:org.apache package org.apache; import java.lang.reflect.Invoc ...
- E20171108-hm
breadcrumb n. 面包屑:面包心; 2.面包的松软(或柔软)部分; n. 网页导航区(a -> b -> c)
- [App Store Connect帮助]三、管理 App 和版本(8)编辑 App 的用户访问权限
对于具有“App 管理”.“客户支持”.“开发者”.“营销”或“销售”职能的特定人员(均不具有“访问报告”职能),您可以限制其在 App Store Connect 帐户中对 App 的访问权限. 必 ...