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. 从django的序列化到rest-framework 序列化

    1.利用Django的view实现返回json数据 from django.views.generic import View from goods.models import Goods class ...

  2. 【Android优化篇】提升Activity加载速度的方法

    文章转自:http://www.jianshu.com/p/2007ca0290d3 作者: CoderFan 前言 这个也是我面试遇到的问题,当时只回答了一种情况,异步加载数据,没想到别的方式,回来 ...

  3. BZOJ1801或洛谷2051 [AHOI2009]中国象棋

    BZOJ原题链接 洛谷原题链接 这题挺难想状态的,刚看题感觉是状压,但数据\(100\)显然不可能. 注意到每行每列只能放\(0\sim 2\)个棋子,所以我们可以将这个写入状态. 设\(f[i][j ...

  4. Java页面中EL的${}与<%= request.getParameter%>有什么区别? el 取不到值

    ${requestScope}操作的是request的作用域,相当于request.getAttribute();不过EL比这个更智能些,它不用强制类型转换就可以拿到了真实对象的值.request.g ...

  5. centos6.5 yum安装postgresql9.3

    rpm -ivh http://download.postgresql.org/pub/repos/yum/9.3/redhat/rhel-6-x86_64/pgdg-centos93-9.3-2.n ...

  6. mybatis @SelectKey加于不加的区别

    正常情况下,我们设置表的主键自增,然后: @Insert("insert into miaosha_order (user_id, goods_id, order_id)values(#{u ...

  7. 2017多校1 hdu-Balala Power!

    其实这道题的思路挺简单的,就是找在第一位置没有出现过并且权值小的那个字母为0. 把a~z按照权值排序,其实难就难在这里,权值很大我们怎么给他排序. 其实可以开个数组来存他们每位数是多少,然后给他们比个 ...

  8. python的数字图像处理学习(3)

    高级滤波: from skimage import data,color,data_dir import matplotlib.pyplot as plt from skimage.morpholog ...

  9. 2018.10.31 NOIP训练 锻造(方程式期望入门题)(期望dp)

    传送门 根据题目列出方程: fi=pi∗(fi−1+fi−2)+(1−pi)∗(fi+1+fi)f_i=p_i*(f_{i-1}+f_{i-2})+(1-p_i)*(f_{i+1}+f_i)fi​=p ...

  10. shell知识积累

    Ubuntu下常用的快捷键:https://blog.csdn.net/u010771356/article/details/53543041 变量名和等号之间不能有空格,变量名中间不能有空格,可以使 ...