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. ACM_寒冰王座(完全背包)

    寒冰王座 Time Limit: 2000/1000ms (Java/Others) Problem Description: 不死族的巫妖王发工资拉,死亡骑士拿到一张N元的钞票(记住,只有一张钞票) ...

  2. 笔记本 windows 10 安装

    开机按快捷键是F12,选择从usb启动.秋叶系统 很好用,推荐使用. 联想笔记本u深度一键u盘启动BIOS设置教程:准备工作:制作好u深度u盘启动盘http://rj.baidu.com/soft/d ...

  3. 为 C# 代码生成 API 文档(自译)

    原文地址:http://broadcast.oreilly.com/2010/09/build-html-documentation-for-y.html#comments Sandcastle 功能 ...

  4. centos源码编译安装nginx过程记录

    前言:Centos系统编译安装LNMP环境是每来一台新服务器或换电脑都需要做的事情.这里仅做一个记录.给初学者一个参考! 一.安装前的环境 这里用的是centos 7系统. 我们默认把下载的软件放在 ...

  5. 关于定位中left和right,top和bottom的权重问题

    关于定位中left和right,top和bottom的权重问题 在共同类中设置了定位并且设置了left等定位,如果你引用这个类并加入其他的类中也有left和right等定位,那么你设置的right或是 ...

  6. PHP开发心得三

    1, JSON在调用json_decode前要检查其中是否含有反斜杠“\”等特殊字符 比如下面这段代码,返回的就是空值,非常坑爹吧. $res = {"Ret":"1&q ...

  7. ThinkPHP系统流程

    1.用户通过入口文件访问控制器2.控制器从模型层中提取数据3.控制器将数据返回模板页面

  8. java设计模式之代理模式模式总结

    定义:代理模式这种设计模式是一种使用代理对象来执行目标对象的方法并在代理对象中增强目标对象方法的一种设计模式. 解读定义: 1.代理对象和目标对象有共同的接口: 2.使用代理对象执行目标对象中的方法: ...

  9. 如何利用CSS中的ime-mode用来控制页面上文本框中的全角/半角输入

    css 之 ime-mode语法:ime-mode : auto | active | inactive | disabled取值:auto : 默认值.不影响ime的状态.与不指定 ime-mode ...

  10. codeforces_304C_数学题

    C. Lucky Permutation Triple time limit per test 2 seconds memory limit per test 256 megabytes input ...