R - Milking Time DP
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 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的更多相关文章
- POJ3616 Milking Time —— DP
题目链接:http://poj.org/problem?id=3616 Milking Time Time Limit: 1000MS Memory Limit: 65536K Total Sub ...
- POJ 3616 Milking Time DP题解
典型的给出区间任务和效益值,然后求最大效益值的任务取法. 属于一维DP了. 一维table记录的数据含义:到当前任务的截止时间前的最大效益值是多少. 注意. 这表示当前任务一定要选择,可是终于结果是不 ...
- poj 3616 Milking Time DP
题意:在给予的N个时间里,奶牛Bessie在M个时间段里进行产奶,但是每次产奶后都要休息R个时间 M个时间段里,分别有开始时间start和结束时间end,和该时间段里产奶的效率efficiency 求 ...
- POJ3616(KB12-R dp)
Milking Time Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9459 Accepted: 3935 De ...
- 概率dp专场
专题链接 第一题--poj3744 Scout YYF I 链接 (简单题) 算是递推题 如果直接推的话 会TLE 会发现 在两个长距离陷阱中间 很长一部分都是重复的 我用 a表示到达i-2步的概率 ...
- 数位DP入门
HDU 2089 不要62 DESC: 问l, r范围内的没有4和相邻62的数有多少个. #include <stdio.h> #include <string.h> #inc ...
- VIJOS1240 朴素的网络游戏[DP]
描述 佳佳最近又迷上了某款类似于虚拟人生的网络游戏.在游戏中,佳佳是某旅行团的团长,他需要安排客户住进旅馆.旅馆给了佳佳的旅行团一个房间数的限制.每一个房间有不同的容纳人数和价钱(这个价格是房间的总价 ...
- 【BZOJ-4518】征途 DP + 斜率优化
4518: [Sdoi2016]征途 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 230 Solved: 156[Submit][Status][ ...
- 【BZOJ-3156】防御准备 DP + 斜率优化
3156: 防御准备 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 951 Solved: 446[Submit][Status][Discuss] ...
随机推荐
- 多维DP UVA 11552 Fewest Flop
题目传送门 /* 题意:将子符串分成k组,每组的字符顺序任意,问改变后的字符串最少有多少块 三维DP:可以知道,每一组的最少块是确定的,问题就在于组与组之间可能会合并块,总块数会-1. dp[i][j ...
- Linux环境下修改MySQL数据库存储引擎
今天在执行Oracle数据库迁移至MySQL数据库时报出了一个错误信息: Specified key was too bytes 百度发现,原来需要更改MySQL数据库的存储引擎为InnoDB,查询目 ...
- js易混API汇总
一:slice()方法 ————————————http://www.w3school.com.cn/jsref/jsref_slice_string.asp ———————————————————— ...
- 【JAVA 学习笔记2】if使用例子
int a =3; if (a%2==0) { System.out.println(a+" 是偶数"); System.out.println(a+" 不是奇数&quo ...
- CAD控件:梦想CAD控件功能更新 清除图上的所有高亮实体
1,修正得组里面的实体,把删除实体也返回的错误 2,修正代理实体改不了颜色问题. 3,修正捕捉块插入点,有时会跑到很远的位置问题. 4.MxDrawChange类增加ToBlockRefe ...
- 解决vue项目运行过程中,npm run dev 报错问题
[方案1] 错误如下: npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! travel@1.0.0 dev: `webpack-dev-server ...
- JS中的let和var的区别
最近很多前端的朋友去面试被问到let和var的区别,其实阮一峰老师的ES6中已经很详细介绍了let的用法和var的区别.我简单总结一下,以便各位以后面试中使用. ES6 新增了let命令,用来声明局部 ...
- selenium爬虫设置headers,代理IP等方法
https://blog.csdn.net/xc_zhou/article/details/80823855
- boostrap标签
字体: <lead>:加强显示 <strong><b>:字体加粗 <i><em>:斜体字 .text-muted:提示,使用浅灰色(#999 ...
- Don't make me think [读书笔记] [思维导图]
<Don't make me think>第3版 内容:解析用户心理,在用户模式.扫描设计.导航设计.主页布局.可用性测试,提出了许多的独到观点及建议. 特色:语言轻松.实在.配有许多 ...