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

思路还是很不对,一开始就没有想到可以直接把间隔加在本次结束时间上。其次,我也想的是对每一小时dp,而正确应该是对每一时间段进行dp
#include<iostream>
#include<algorithm>
#include<string.h>
#include<string>
using namespace std;
struct node{
int start,end,val;
bool operator <(const node &a)const{
return start<a.start;
}
}nn[];
int dp[];
int main(){
int n,m,r;
cin>>n>>m>>r;
for(int i=;i<m;i++){
cin>>nn[i].start>>nn[i].end>>nn[i].val;
nn[i].end+=r;
}
sort(nn,nn+m);
for(int i=;i<m;i++){
dp[i]=nn[i].val;
for(int j=;j<i;j++){
if(nn[j].end<=nn[i].start){
dp[i]=max(dp[i],dp[j]+nn[i].val);
}
}
}
cout << *max_element(dp, dp + m) << endl;
return ;
}

POJ3616--Milking Time(动态规划)的更多相关文章

  1. 动态规划 POJ3616 Milking Time

    #include <iostream> #include <cstdio> #include <algorithm> using namespace std; st ...

  2. POJ - 3616 Milking Time (动态规划)

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

  3. poj3616 Milking Time(状态转移方程,类似LIS)

    https://vjudge.net/problem/POJ-3616 猛刷简单dp的第一天第二题. 这道题乍一看跟背包很像,不同的在于它是一个区间,背包是定点,试了很久想往背包上套,都没成功. 这题 ...

  4. D - Milking Time 动态规划

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

  5. POJ3616 Milking Time —— DP

    题目链接:http://poj.org/problem?id=3616 Milking Time Time Limit: 1000MS   Memory Limit: 65536K Total Sub ...

  6. POJ3616 Milking Time【dp】

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

  7. poj-3616 Milking Time (区间dp)

    http://poj.org/problem?id=3616 bessie是一头工作很努力的奶牛,她很关心自己的产奶量,所以在她安排接下来的n个小时以尽可能提高自己的产奶量. 现在有m个产奶时间,每个 ...

  8. POJ3616 Milking Time 简单DP

    注意0,1,.....,N是时间点,i~i+1是时间段 然后就是思路:dp[i]代表到时间点 i 获得的最大价值, 1:dp[i]=max(dp[i],dp[s-r]+e),表示有以s为开头,i为结尾 ...

  9. poj3616 Milking Time

    思路: dp. 实现: #include <iostream> #include <cstdio> #include <algorithm> using names ...

  10. 《挑战程序设计竞赛》2.3 动态规划-基础 POJ3176 2229 2385 3616 3280

    POJ3176 Cow Bowling 题意 输入一个n层的三角形,第i层有i个数,求从第1层到第n层的所有路线中,权值之和最大的路线. 规定:第i层的某个数只能连线走到第i+1层中与它位置相邻的两个 ...

随机推荐

  1. Vue 插件和Preset

    插件和Preset 插件 Vue CLI 使用了一套基于插件的架构 Vue CLI 使用了一套基于插件的架构.如果你查阅一个新创建项目的 package.json,就会发现依赖都是以 @vue/cli ...

  2. 5F - Coin Change

    Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We want to make c ...

  3. (转)silverlight应用程序中未处理的错误代码:2104 类别:InitializeError

        解决方案:第一步:默认网站--属性-----http头 第二步:点击mime类型: 第三步:点击新建: 第四步:输入扩展名以及类型: (1) 扩展名:.xaml MIME类型:applicat ...

  4. P<0.05就够了?还要校正!校正!3个方法献上

    P<0.05就够了?还要校正!校正!3个方法献上 (2017-01-03 17:55:12) 转载▼   分类: 数理统计 (转  医生科研助手 解螺旋 微信公众号)   当有多组数据要比较时, ...

  5. [Robot Framework] 执行时报 webdriver 异常

    在用Robot Framework通过Selenium2Library做web界面自动化测试的时候,报webdriver的错误: 此种情况是因为WebDriver的版本与浏览器的版本不对应. WebD ...

  6. mysql 5.7.10 下互为主备配置

    mysql安装方法这里就不在介绍,网上有很多教程 环境介绍: A主机: win2008_x64+mysql5.7.10 64位,ip192.168.7.180 B主机: win2008_x64+mys ...

  7. Bootstrap学习遇到的role属性--- 无障碍网页应用属性

    以前接触过Bootstrap,但也只是仅仅接触,现在重新学习下,今天看到一个例子中的属性有一个role, 查阅资料发现这个是--WAI-ARIA无障碍设计属性: 通俗说是该设计为了一些盲人,失聪,残疾 ...

  8. 如何上传Packages到PyPI并批量抓取

    1.如何上传包到PyPI ? 更新中... 2.批量抓取simple网站第三方模块 https://pypi.python.org/simple/ 3. 第三方模块的安装和使用 python  set ...

  9. python程序保存成二进制(不公开源码)

    https://www.tiobe.com/ (python语言排行榜) pip install pyinstaller pyinstaller test.py ./test

  10. MySQL查找SQL耗时瓶颈 SHOW profiles

    http://blog.csdn.net/k_scott/article/details/8804384 1.首先查看是否开启profiling功能 SHOW VARIABLES LIKE '%pro ...