poj 3616 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 ( ≤ N ≤ ,,) hours (conveniently labeled ..N-) so that she produces as much milk as possible. Farmer John has a list of M ( ≤ M ≤ ,) possibly overlapping intervals in which he is available for milking. Each interval i has a starting hour ( ≤ starting_houri ≤ N), an ending hour (starting_houri < ending_houri ≤ N), and a corresponding efficiency ( ≤ efficiencyi ≤ ,,) 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 ( ≤ 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 : Three space-separated integers: N, M, and R
* Lines ..M+: Line i+ describes FJ's ith milking interval withthree space-separated integers: starting_houri , ending_houri , and efficiencyi
Output
* Line : The maximum number of gallons of milk that Bessie can product in the N hours
Sample Input
Sample Output
Source
for(int i=1;i<=m;i++){
			dp[i]=cows[i].c;
		}
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<stdlib.h>
using namespace std;
#define N 1000006
#define M 1006
int n,m,r;
struct Node{
int s,e;
int c;
}cows[M];
bool cmp(Node a,Node b){
if(a.s!=b.s)
return a.s<b.s;
return a.e<b.e;
}
int dp[M];//dp[i]表示取到第i段时间段时的最大值
int main()
{
while(scanf("%d%d%d",&n,&m,&r)==){
for(int i=;i<=m;i++){
scanf("%d%d%d",&cows[i].s,&cows[i].e,&cows[i].c);
}
sort(cows+,cows+m+,cmp);
memset(dp,,sizeof(dp));
for(int i=;i<=m;i++){
dp[i]=cows[i].c;
}
//dp[1]=cows[1].c;
int ans=;
for(int i=;i<=m;i++){
for(int j=;j<i;j++){
if(cows[i].s>=cows[j].e+r){
dp[i]=max(dp[i],dp[j]+cows[i].c);
}
}
ans=max(dp[i],ans);
// printf("---%d\n",ans);
}
printf("%d\n",ans);
}
return ;
}
poj 3616 Milking Time(dp)的更多相关文章
- 【POJ】3616 Milking Time(dp)
		
Milking Time Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10898 Accepted: 4591 Des ...
 - 【POJ 3071】 Football(DP)
		
[POJ 3071] Football(DP) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4350 Accepted ...
 - POJ 3616 Milking Time(加掩饰的LIS)
		
传送门: http://poj.org/problem?id=3616 Milking Time Time Limit: 1000MS Memory Limit: 65536K Total Sub ...
 - POJ 3616 Milking Time 【DP】
		
题意:奶牛Bessie在0~N时间段产奶.农夫约翰有M个时间段可以挤奶,时间段f,t内Bessie能挤到的牛奶量e.奶牛产奶后需要休息R小时才能继续下一次产奶,求Bessie最大的挤奶量.思路:一定是 ...
 - POJ 3858 Hurry Plotter(DP)
		
Description A plotter is a vector graphics printing device that connects to a computer to print grap ...
 - Milking Time(DP)
		
个人心得:一开始自己找状态,是这么理解的,只要前面一个满足就等于此时的值加上d(n-1),否则就是不挖此时的比较d(n-1)和 d(n-2)+cost,不过仔细一想忽略了很多问题,你无法确定n-2和此 ...
 - POJ - 2385 Apple Catching (dp)
		
题意:有两棵树,标号为1和2,在Tmin内,每分钟都会有一个苹果从其中一棵树上落下,问最多移动M次的情况下(该人可瞬间移动),最多能吃到多少苹果.假设该人一开始在标号为1的树下. 分析: 1.dp[x ...
 - POJ 3616 Milking Time(最大递增子序列变形)
		
题目链接:http://poj.org/problem?id=3616 题目大意:给你时间N,还有M个区间每个区间a[i]都有开始时间.结束时间.生产效率(时间都不超过N),只能在给出的时间段内生产, ...
 - POJ 3616 Milking Time  ——(记忆化搜索)
		
第一眼看是线段交集问题,感觉不会= =.然后发现n是1000,那好像可以n^2建图再做.一想到这里,突然醒悟,直接记忆化搜索就好了啊..太蠢了.. 代码如下: #include <stdio.h ...
 
随机推荐
- struts配置,略记
			
<!-- <listener> <listener-class>org.springframework.web.context.ContextLoaderListener ...
 - [RxJS] Wrap up
			
Last thing to do is clean the score box and input, also auto foucs on input when click start. const ...
 - 《31天成为IT服务达人》--机遇篇(二)
			
1 第二章 机遇就是选择大于努力 年假设你一咬牙(或者在晚点)买了房,十年的巨幅增值,比你如今干哪行都赚得快,可是往往有选择就有痛苦,这样的痛苦来至于对未知的恐惧和现实须要一定的付出.作为 ...
 - QiniuUpload- 一个方便用七牛做图床然后插入markdown的小工具
			
最近一段时间有用markdown做笔记,其他都好,但是markdown插入图片挺麻烦的,特别是想截图之后直接插入的时候.需要首先把图片保存了,然后还要上传到一个地方生成链接才能插入.如果有个工具可以直 ...
 - Android 编程下 Activity 的创建和应用退出时的销毁
			
为了确保对应用中 Activity 的创建和销毁状态进行控制,所以就需要一个全局的变量来记录和销毁这些 Activity.这里的大概思路是写一个类继承 Application,并使获取该 Applic ...
 - (转)修改IIS默认的localhost名称
			
看惯了http://localhost在本地测试的域名,想换种写法行不行,比如说想变成http://www.ceo.com,但网页访问仍然是原来http://localhost的内容,如何做到呢? 可 ...
 - DropDownList绑定数据
			
DDLName.DataSource = myRd;DDLName.DataTextField = "name";//要绑定的字段DDLName.DataValueField = ...
 - UC浏览器 分享到朋友圈和微信好友
			
用手机UC浏览器访问新浪微博,会注意到有这样的两个分享按钮: 在手机端浏览器里,点击分享按钮,就可以启动微信客户端并分享到微信.研究了下其源代码,存在这样的一个js:http://mjs.sinaim ...
 - 给一组a标签当前页a标签加class
			
<script type="text/javascript"> $(document).ready(function(){ $(".links .topbg_ ...
 - hdu 2564 词组缩写
			
Problem Description 定义:一个词组中每个单词的首字母的大写组合称为该词组的缩写. 比如,C语言里常用的EOF就是end of file的缩写. Input 输入的第一行是一个整数T ...