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. 洛谷2019 3月月赛 T1

    题干 2019第一次月赛 我只有255pts T1还是比较水的... 海星 T1一道简单的模拟(就是有坑..导致很多人不能一次性AC 比如说我) _3个坑点 1.位数问题 2.-0 3.0... #i ...

  2. tomcat 参数调优

    JAVA_OPTS="-Xms2g -Xmx2g  -XX:+PrintGCDetails -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath= ...

  3. 区间DP UVA 1351 String Compression

    题目传送门 /* 题意:给一个字符串,连续相同的段落可以合并,gogogo->3(go),问最小表示的长度 区间DP:dp[i][j]表示[i,j]的区间最小表示长度,那么dp[i][j] = ...

  4. mysql 5.7 显示中文

    思路: 那网页xxx.php的工作过程就是这样的啦:从xxx.php页面上输入汉字,因为xxx.php是UTF8编码的,所以xxx.php以UTF8格式转换输入的汉字,然后以UTF8提交给mysql, ...

  5. hdu 4104 Discount

    http://acm.hdu.edu.cn/showproblem.php?pid=4104 一开始还以为这题是背包,然后优化下这个背包,但是一直都优化不出来. 然后题解是直接模拟而已,唉 先从小到大 ...

  6. leetcode221 Maximal Square

    思路: dp. 实现: class Solution { public: int maximalSquare(vector<vector<char>>& matrix) ...

  7. cocos2d-x android 环境部署

    1.下载jdk http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 2.下载 and ...

  8. 解决TeamViewer的“现在无法捕捉画面。可能由于快速切换或者远程桌面断开或者最小化”问题

    公司项目接近尾声,因为测试的需要,就在客户局域网内部搭建了几台虚拟机做为服务器给客户测试用. 虚拟机环境:win2008R2 原先在客户那边用远程登录虚拟机操作,但考虑到回公司后无法远程登录,所以安装 ...

  9. MFC_2.2 编辑框和文本控件

    编辑框和文本控件 1.拖控件 2.绑定变量.用户名密码编辑框控件类型.取名字.用户协议用值类型,默认CString. 设置属性.用户类型.选择mustiline TRUE. AOTO HScroll ...

  10. jmeter插件之PerfMon

    PerfMon是jmeter监控系统资源的一款插件,可以用来监控系统的CPU/内存/IO等性能指标. 一.要准备好的插件:JMeterPlugins-Standard-1.4.0(pwd:cjqd)或 ...