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