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 ...
随机推荐
- vue-cli 脚手架总结
> vue-cli 的脚手架项目模板有browserify 和 webpack , 现在自己在用的是webpack , 官网给出了两个模板: webpack-simple 和 webpack 两 ...
- Opencv 简单的图片显示
#include <opencv\cv.h> #include <opencv\highgui.h> #include <opencv\cxcore.h> int ...
- android_launcher的源码详细分析
转载请注明出处:http://blog.csdn.net/fzh0803/archive/2011/03/26/6279995.aspx 去年做了launcher相关的工作,看了很长时间.很多人都在修 ...
- install-file -Dfile=J:\project01\workspace\service\lib\javapns-jdk16-163.jar -DgroupId=org.json -Dar
今天在开发项目的时候发现了一个问题,所以通过博客来记录起来! 为了以后在问题的解决方面能得到借鉴! 问题的现象是这种: 这样会报错的.pom.xml文件他在编译.检查他的文件语法的时候是须要參考库中的 ...
- HDOJ 4937 Lucky Number
当进制转换后所剩下的为数较少时(2位.3位),相应的base都比較大.能够用数学的方法计算出来. 预处理掉转换后位数为3位后,base就小于n的3次方了,能够暴力计算. . .. Lucky Numb ...
- c++11 线程:让你的多线程任务更轻松
介绍 本文旨在帮助有经验的Win32程序员来了解c++ 11线程库及同步对象 和 Win32线程及同步对象之间的区别和相似之处. 在Win32中,所有的同步对象句柄(HANDLE)是全局句柄.它们 ...
- 解决Fetching android sdk component information加载过久问题
安装完成后,如果直接启动,Android Studio会去获取 android sdk 组件信息,这个过程相当慢,还经常加载失败,导致Android Studio启动不起开.解决办法就是不去获取and ...
- js_day13
- 文本框按键事件onkeydown、onkeypress、onkeyup区别
当我们在搜索时,会用到这几个事件 onkeydown 是指鼠标按下的那一刻,此时用户不知道按了什么,文本框也不会显示,首先触发的事件 onkeypress 是指鼠标按下然后松开的瞬间,此时仍然获取不到 ...
- Localdb Attach Problem
在进行code first的迁移时,update-database后默认在App_data文件夹下会新建数据库,如果删除了在使用update-database命令会出现以下错误: Cannot att ...