Milking Time

Time Limit: 1000MS    Memory Limit: 65536K

Total Submissions: 9459  Accepted: 3935

 

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

Source

 
有将近一个月没做题,练一下手感。
 //2017-05-16
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const int M = ;
int dp[M];
struct Milk
{
int bg, ed, eff;
bool operator<(Milk x) const{
return ed < x.ed;
}
}milk[M]; int main()
{
int n, m, r;
while(scanf("%d%d%d", &n, &m, &r)!=EOF)
{
memset(dp, , sizeof(dp));
for(int i = ; i < m; i++){
scanf("%d%d%d", &milk[i].bg, &milk[i].ed, &milk[i].eff);
}
sort(milk, milk+m);
int ans = ;
for(int i = ; i < m; i++){
if(milk[i].ed > n)break;
dp[i] = milk[i].eff;
for(int j = ; j < i; j++){
if(milk[i].bg-r >= milk[j].ed){
dp[i] = max(dp[i], dp[j]+milk[i].eff);//dp[i]表示到第i个区间的最大值
}else break;
}
if(dp[i] > ans)ans = dp[i];
}
printf("%d\n", ans);
} return ;
}

最新文章

  1. mybatis-generator 1.3.5支持流式 fluent 方法
  2. dbflow 批量 增删查改
  3. OC中的那些String
  4. adb server is out of date killing... 的解决办法
  5. 代码演示 .NET 4.5 自带的 ReadonlyCollection 的使用
  6. 【php学习】字符串操作
  7. nsarray排序
  8. (四)Ubuntu 14.04 文件服务器--samba的安装和配置
  9. 001.XE3添加TPerlRegEx
  10. Linq中SingleOrDefault、FirstOrDefault的用法
  11. CVPR 2013 录用论文【待更新】
  12. svn过滤文件配置
  13. [蓝桥杯]2015蓝桥省赛B组题目及详解
  14. Bugku-CTF之cookies欺骗
  15. c++ virtual 记录
  16. JS数字指定长度不足前补零的实现
  17. Spark新手入门——1.Scala环境准备
  18. pycharm永久激活(转)
  19. 【emWin】例程三十:窗口对象——Multiedit
  20. mysql设置指定ip访问,用户权限相关操作

热门文章

  1. 09_python_初始函数
  2. Swift5 语言参考(五) 语句
  3. 链表(上):如何实现LRU缓存淘汰算法?
  4. python ftplib模块使用
  5. 文件分享系统(Django)
  6. Python相关在线文档手册地址
  7. Linux驱动:I2C驱动编写要点
  8. css实现图片垂直居中
  9. ASP.NET Core 中使用 Hangfire 定时启动 Scrapyd 爬虫
  10. Mac 下配置 Python 开发环境