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: NM, 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 Nhours

Sample Input

12 4 2
1 2 8
10 12 19
3 6 24
7 10 31

Sample Output

43
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; #define MAXN 1003
/*
最长递增子序列的变形
*/
int n,m,r;
struct node
{
int beg,end,v,sum;
}a[MAXN];
bool cmp(node a,node b)
{
return a.beg<b.beg;
}
int main()
{
scanf("%d%d%d",&n,&m,&r);
for(int i=;i<m;i++)
{
scanf("%d%d%d",&a[i].beg,&a[i].end,&a[i].v);
a[i].sum = a[i].v;
}
sort(a,a+m,cmp);
int ans = ;
for(int i=;i<m;i++)
{
int Max = ;
for(int j=;j<i;j++)
{
if(a[i].beg-a[j].end>=r)
{
Max = max(Max,a[j].sum);
}
}
a[i].sum += Max;
ans = max(a[i].sum,ans);
}
printf("%d\n",max(ans,a[].v));
return ;
}

R - Milking Time DP的更多相关文章

  1. POJ3616 Milking Time —— DP

    题目链接:http://poj.org/problem?id=3616 Milking Time Time Limit: 1000MS   Memory Limit: 65536K Total Sub ...

  2. POJ 3616 Milking Time DP题解

    典型的给出区间任务和效益值,然后求最大效益值的任务取法. 属于一维DP了. 一维table记录的数据含义:到当前任务的截止时间前的最大效益值是多少. 注意. 这表示当前任务一定要选择,可是终于结果是不 ...

  3. poj 3616 Milking Time DP

    题意:在给予的N个时间里,奶牛Bessie在M个时间段里进行产奶,但是每次产奶后都要休息R个时间 M个时间段里,分别有开始时间start和结束时间end,和该时间段里产奶的效率efficiency 求 ...

  4. POJ3616(KB12-R dp)

    Milking Time Time Limit: 1000MS    Memory Limit: 65536K Total Submissions: 9459  Accepted: 3935   De ...

  5. 概率dp专场

    专题链接 第一题--poj3744 Scout YYF I  链接 (简单题) 算是递推题 如果直接推的话 会TLE 会发现 在两个长距离陷阱中间 很长一部分都是重复的 我用 a表示到达i-2步的概率 ...

  6. 数位DP入门

    HDU 2089 不要62 DESC: 问l, r范围内的没有4和相邻62的数有多少个. #include <stdio.h> #include <string.h> #inc ...

  7. VIJOS1240 朴素的网络游戏[DP]

    描述 佳佳最近又迷上了某款类似于虚拟人生的网络游戏.在游戏中,佳佳是某旅行团的团长,他需要安排客户住进旅馆.旅馆给了佳佳的旅行团一个房间数的限制.每一个房间有不同的容纳人数和价钱(这个价格是房间的总价 ...

  8. 【BZOJ-4518】征途 DP + 斜率优化

    4518: [Sdoi2016]征途 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 230  Solved: 156[Submit][Status][ ...

  9. 【BZOJ-3156】防御准备 DP + 斜率优化

    3156: 防御准备 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 951  Solved: 446[Submit][Status][Discuss] ...

随机推荐

  1. mydatepicker97 日历控件

    官方教程: http://www.my97.net/

  2. [LOJ#10064]黑暗城堡

    Description 在顺利攻破 Lord lsp 的防线之后,lqr 一行人来到了 Lord lsp 的城堡下方.Lord lsp 黑化之后虽然拥有了强大的超能力,能够用意念力制造建筑物,但是智商 ...

  3. hdu5926Mr. Frog’s Game

    Mr. Frog's Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  4. VC++常见错误原因解析--error LNK2019: 无法解析的外部符号 "public: void __thiscall

    根据个人遇到这个错误时的记录,原因可以分为一下几种: 原因一: 只是在.h里面声明了某个方法, 没有在cpp里面实现 . 具体讲,有时候在头文件中声明了需要的方法,确实忘记了在源文件中实现: 有时候在 ...

  5. get、post、put、delete、head请求方式

    对资源的增,删,改,查操作,其实都可以通过GET/POST完成,不一定要用PUT和DELETE. 一:Jersey框架,实现了restful风格,常用的注解@GET.@POST.@PUT.@DELET ...

  6. python自动化--语言基础三字典、函数、全局/局部变量

    字典 dict1 = {,'class':'first'} print(dict1.keys()) #打印所有的key值 print(dict1.values()) #打印所有的values值 pri ...

  7. Verification Mind Games---how to think like a verifier像验证工程师一样思考

    1. 有效的验证需要验证工程师使用不同于设计者的思维方式思考问题.具体来说,验证更加关心在严格遵循协议的基础上发现设计里面的bug,搜索corner cases,对设计的不一致要保持零容忍的态度. m ...

  8. Spartan6系列之器件引脚功能详述

    1.   Spartan-6系列封装概述 Spartan-6系列具有低成本.省空间的封装形式,能使用户引脚密度最大化.所有Spartan-6 LX器件之间的引脚分配是兼容的,所有Spartan-6 L ...

  9. SDK_进度条和滑块

    进度条和滑块 进度条和滑块属于通用控件,通用控件的使用需要加 CommCtrl.h 头文件 如何初始化进度条和滑块的数值范围和默认的位置 // 设置默认的范围值SendDlgItemMessage(h ...

  10. CAD得到ImageMark数据(com接口VB语言)

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...