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. spring data elasticsearch的 @Documnet 和 @Field 注解

    @Documnet 注解 public @interface Document { String indexName(); //索引库的名称,个人建议以项目的名称命名 String type() de ...

  2. 同余模定理 HDOJ 5373 The shortest problem

    题目传送门 /* 题意:题目讲的很清楚:When n=123 and t=3 then we can get 123->1236->123612->12361215.要求t次操作后, ...

  3. ACM_递推题目系列之三放苹果(递推dp)

    递推题目系列之三放苹果 Time Limit: 2000/1000ms (Java/Others) Problem Description: 把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放 ...

  4. Windows平台下Oracle实例启动过程中日志输出

    Windows平台下Oracle实例启动过程中日志输出记录. 路径:D:\app\Administrator\diag\rdbms\orcl\orcl\trace\alert_orcl.log 输出内 ...

  5. 关于dbms_output包的使用

    General Source {ORACLE_HOME}/rdbms/admin/dbmsotpt.sql First Available 7.3.4 Data Types TYPE chararr ...

  6. Log4Net学习笔记(1)-完整的例子

    一.开发环境 编译器:VS2013 .Net版本:4.5 二.开发流程 1.从nuget上获取log4net 2.配置log4net的配置文件 <?xml version="1.0&q ...

  7. MVC之参数验证(三)

    在实际开发中,项目经理会一直强调一句话,永远不要相信客户端的数据(前端可以不用验证,但是后端必须验证).大家同意这样的说法吧..新端验证毋庸质疑JS验证,提高用户体验我们不得不添加一些与后端一致的验证 ...

  8. Android 仿 新闻阅读器 菜单弹出效果(附源码DEMO)

    这一系列博文都是:(android高仿系列)今日头条 --新闻阅读器 (一) 开发中碰到问题之后实现的,觉得可能有的开发者用的到或则希望独立成一个小功能DEMO,所以就放出来这么一个DEMO. 原本觉 ...

  9. dive into python:模块的导入和搜索文件路径的配置

    1.Python中导入模块:import sys:相当于Java中的导入包.类. 比如,我们导入sys模块,使用:import sys; 2.Python中调用函数的时候,会从默认配置的库文件夹中(s ...

  10. Linux下如何从mysql数据库里导出导入数据

    https://blog.csdn.net/u012884402/article/details/47337701 一. 表的导入 1.进入数据库 mysql 数据库名 2.​查看表 show tab ...