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. 使用java5的注解和Sping/AspectJ的AOP 来实现Memcached的缓存

    使用java5的注解和Sping/AspectJ的AOP 来实现Memcached的缓存 今天要介绍的是Simple-Spring-Memcached,它封装了对MemCached的调用,使MemCa ...

  2. c# 多个事件公用一个相应方法判断事件来源

    假设下边的相应方法有多个事件共同使用.根据事件的sender 判断来源,做相应的处理 假设事件来源DataManSystem;private void OnSystemConnected(object ...

  3. andorid 配置器组件和提示消息

    .xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android ...

  4. 大数加法java版

    import java.util.*; import java.math.BigDecimal; public class Numadd{ public static void main(String ...

  5. Autel MaxiSys MS906TS tire pressure settings Lexus LS460h

    Use AUTEL MaxiSYS MS906TS error reader to install tire pressure Lexus LS460h in Vung Tau. Make : Lex ...

  6. 简单使用DESeq2/EdgeR做差异分析

    简单使用DESeq2/EdgeR做差异分析 Posted: 五月 07, 2017  Under: Transcriptomics  By Kai  no Comments DESeq2和EdgeR都 ...

  7. Vuebnb 一个用 vue.js + Laravel 构建的全栈应用

    今年我一直在写一本新书叫全栈Vue网站开发:Vue.js,Vuex和Laravel.它会在Packt出版社在2018年初出版. 这本书是围绕着一个案例研究项目,Vuebnb,简单克隆Airbnb.在这 ...

  8. 配置nginx1.8支持thinkPHP3.2 pathinfo模式

    nginx 下conf/nginx.conf 或者自己的vhosts更改以前的参数 location / { root   html; index  index.html index.htm inde ...

  9. [Hbase]Hbase章3 Hbase单点故障

    很长一段时间以来,一个region同一时间只能在一台RS(Region Server)中打开.如果一个region同时在多个RS上打开,就是multi-assign问题,会导致数据不一致甚至丢数据的情 ...

  10. proguard-rules.pro、混淆、导jar包

    前记: 买了一个<精通Android Studio>本来最想看的是关于混淆导jar包的,哪知道没有,有点小失望. 好吧,自己来. 在用Android Studio开发的时候,把minify ...