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 (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 N hours

Sample Input

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

Sample Output

43

先对区间左端点从小到大排序,相同时右端点小的在前。然后从前往后依次处理,设dp[i]表示选第i个区间可以获得的最大值,那么对i之前任意与i相距大于等于r的区间j,dp[i]=max(dp[i],dp[j]+s[i].w)

#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <map>
#include <vector>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <limits>
#include <new>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <ctime>
using namespace std;struct milk
{int x, y, w;bool operator < (const milk& b) const{if (x == b.x)return y < b.y;return x < b.x;}
};int main()
{int n, m, r, dp[1005];milk s[1005];cin >> n >> m >> r;for (int i = 0; i < m; ++i)scanf("%d%d%d", &s[i].x, &s[i].y, &s[i].w);sort(s, s+m);for (int i = 0; i < m; ++i)dp[i] = s[i].w;int ans = 0;for (int i = 0; i < m; ++i){for (int j = 0; j < i; ++j)if (s[i].x >= s[j].y + r)dp[i] = max(dp[i], dp[j]+s[i].w);ans = max(ans, dp[i]);}printf("%d\n", ans);return 0;
}

poj3616(Milking Time)相关推荐

  1. kuangbin专题十二 基础DP

    kuangbin专题十二 基础DP A - HDU1024 Max Sum Plus Plus B - HDU1029 Ignatius and the Princess IV C - HDU1069 ...

  2. Milking Time(POJ-3616)

    Problem Description Bessie is such a hard-working cow. In fact, she is so focused on maximizing her ...

  3. Milking Cows 挤牛奶

    1.2.1 Milking Cows 挤牛奶 Time Limit: 1 Sec  Memory Limit: 64 MB Submit: 554  Solved: 108 [Submit][Stat ...

  4. POJ 2112 Optimal Milking(二分+最大流)

    POJ 2112 Optimal Milking 题目链接 题意:给定一些机器和奶牛,在给定距离矩阵,(不在对角线上为0的值代表不可达),每一个机器能容纳m个奶牛.问全部奶牛都能挤上奶,那么走的距离最 ...

  5. 1642: [Usaco2007 Nov]Milking Time 挤奶时间(dp)

    1642: [Usaco2007 Nov]Milking Time 挤奶时间 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 935  Solved: 5 ...

  6. J - Milking Time POJ - 3616(dp动态规划)

    Bessie is such a hard-working cow. In fact, she is so focused on maximizing her productivity that sh ...

  7. 动态规划训练22 [Milking Time POJ - 3616 ]

    Milking Time POJ - 3616 说实话这道题目非常简单,本质上就是 多段有向图的求最大值问题.稍微变化的地方在于这个的的有向边没有那么明显 ,而是需要自己去寻找 如果任务i到任务j之间 ...

  8. 【POJ - 3616】Milking Time (贪心+dp)

    题干: Bessie is such a hard-working cow. In fact, she is so focused on maximizing her productivity tha ...

  9. dp打开思路3:HDU1069 POJ3616 POJ1088

    HDU 1069 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 题意:把给定的长方体(不限)叠加在一起,叠加的条件是,上面一个长方体的长和宽都 ...

  10. Milking Time【动态规划-dp】

    Milking Time POJ - 3616 Bessie is such a hard-working cow. In fact, she is so focused on maximizing ...

最新文章

  1. How to check Laravel version?
  2. Gh0st源码学习(一)前期准备工作
  3. 暴库也不怕!EF Core加密存储数据
  4. 听小鹏讲废话之OSI
  5. Spring Boot笔记-@ComponentScan初步解析
  6. OrCAD PSpice仿真流程——Cadence 17.4
  7. 《欲罢不能:刷屏时代如何摆脱行为上瘾》书摘
  8. Oracle数据库恢复删除数据的方法
  9. 诛仙3饮马江南服务器信息,12月29日全服停机更新维护公告
  10. 关于调研微信的几点理解
  11. LiveZilla管理员密码忘记了如何恢复?How can I change the administrator password
  12. Something about 博弈~(updating...)
  13. KUKA机器人使用PLC外部自动运行配置使用方法
  14. 多重继承--读松本行弘的程序世界
  15. 我如何构建一个交互式仪表板Web应用程序以可视化拳击数据
  16. 生活中的货币时间价值 网课答案
  17. 树莓派挂载和卸载U盘或移动硬盘
  18. python基础编程简单案例:购买商品
  19. RestTemplete
  20. 嵌入式 Linux LED 驱动开发实验

热门文章

  1. 观察者模式之:从三国混战看创业者精神。
  2. 晶体(谐振器)震荡电路与参数
  3. 【bootstrap】-----使用核心
  4. nginx反向代理解决跨域
  5. 很吊炸天的Xcode插件,你想要的这都有
  6. C#OOP之十一 委托和事件
  7. codeforces629C Famil Door and Brackets (dp)
  8. Apache Curator入门实战
  9. SQL Server 中添加表注释
  10. [原]tornado源码分析系列(二)[网络层 IOLoop类]