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

 
 
 
dp,注意初始化,

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)的更多相关文章

  1. 【POJ】3616 Milking Time(dp)

    Milking Time Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10898   Accepted: 4591 Des ...

  2. 【POJ 3071】 Football(DP)

    [POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted ...

  3. POJ 3616 Milking Time(加掩饰的LIS)

    传送门: http://poj.org/problem?id=3616 Milking Time Time Limit: 1000MS   Memory Limit: 65536K Total Sub ...

  4. POJ 3616 Milking Time 【DP】

    题意:奶牛Bessie在0~N时间段产奶.农夫约翰有M个时间段可以挤奶,时间段f,t内Bessie能挤到的牛奶量e.奶牛产奶后需要休息R小时才能继续下一次产奶,求Bessie最大的挤奶量.思路:一定是 ...

  5. POJ 3858 Hurry Plotter(DP)

    Description A plotter is a vector graphics printing device that connects to a computer to print grap ...

  6. Milking Time(DP)

    个人心得:一开始自己找状态,是这么理解的,只要前面一个满足就等于此时的值加上d(n-1),否则就是不挖此时的比较d(n-1)和 d(n-2)+cost,不过仔细一想忽略了很多问题,你无法确定n-2和此 ...

  7. POJ - 2385 Apple Catching (dp)

    题意:有两棵树,标号为1和2,在Tmin内,每分钟都会有一个苹果从其中一棵树上落下,问最多移动M次的情况下(该人可瞬间移动),最多能吃到多少苹果.假设该人一开始在标号为1的树下. 分析: 1.dp[x ...

  8. POJ 3616 Milking Time(最大递增子序列变形)

    题目链接:http://poj.org/problem?id=3616 题目大意:给你时间N,还有M个区间每个区间a[i]都有开始时间.结束时间.生产效率(时间都不超过N),只能在给出的时间段内生产, ...

  9. POJ 3616 Milking Time ——(记忆化搜索)

    第一眼看是线段交集问题,感觉不会= =.然后发现n是1000,那好像可以n^2建图再做.一想到这里,突然醒悟,直接记忆化搜索就好了啊..太蠢了.. 代码如下: #include <stdio.h ...

随机推荐

  1. C#使用WebKitBrowser.dll填坑记

    .Net 自带的 Webbrowser 有着太多的平台限制.对于用户体验之上的今天,这无疑是一个噩梦, 然后就开始找 .Net下的WebKitBrowser.dll (后面提供下载) 从开源网站下到程 ...

  2. (转)iOS Wow体验 - 第四章 - 为应用的上下文环境而设计

    本文是<iOS Wow Factor:Apps and UX Design Techniques for iPhone and iPad>第四章译文精选,其余章节将陆续放出.上一篇:Wow ...

  3. jQuery插件开发 格式与解析2

    最近忙里偷闲玩一下js插件,经过自身的练习,感觉js插件还是挺好玩的.特此作如下笔记,给自己留个印象.例子形如: (1)类插件:classTool.js Code: (function($,expor ...

  4. 关于Go语言共享内存操作的小实例

    <strong style="margin: 0px; padding: 0px; border: 0px; font-size: 15px; font-weight: bold; c ...

  5. Android TextView中实现点击文本超链接(无下划线)的封装类

    android中有的时候须要在TextView上设置一些超链接,点击这些超链接时进行一些操作.比如新浪微博上的一些keyword,点击时会跳转到对应的页面. 怎样实现我们就直接看源代码吧. /** * ...

  6. stat(),lstat(),fstat() 获取文件/目录的相关信息

    stat 的使用 Linux有个命令,ls -l,效果如下: 这个命令能显示文件的类型.操作权限.硬链接数量.属主.所属组.大小.修改时间.文件名.它是怎么获得这些信息的呢,请看下面的讲解. stat ...

  7. web负载均衡整理

    参考:http://www.cnblogs.com/lovingprince/archive/2008/11/13/2166350.html http://www.cnblogs.com/loving ...

  8. Palindrome Number 回文数

    判断一个数字是否是回文数,尝试不用其他额外空间. 注意: 负数也有可能成为回文数吗? 如果你想让int转为string,注意不用其他空间这个约束. 你也可以翻转一个int,但是有可能会溢出.     ...

  9. VC防止程序被多次运行 互斥体方法

    BOOL CXXXApp::InitInstance() //函数内添加代码 HANDLE hMutex=CreateMutex(NULL,TRUE,"test"); // 用于检 ...

  10. int.Tryparse() 、int.parse()、Convert.To32() 的区别

    int.Tryparse()  Int32.TryParse(source, result)则无论如何都不抛出异常,只会返回true或false来说明解析是否成功,如果解析失败,调用方将会得到0值. ...