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. Sonar配置与使用

    一.前置条件: 安装工具如下: JDK MySql服务器 SonarQube SonarScanner 从官网下载安装包进行安装,具体安装步骤略 二.配置 MySql配置: 打开SQL,创建sonar ...

  2. C#做一个写txt文件流的测试,为什么配置低的机器写入的还快

    测试机:笔记本i7 8G 固态硬盘 由于采取读码写入txt方式, 读码频率挺高,文件名为日期格式,当前采用每次读码打开文件写入的方式, 为什么没用sb,因为怕断电情况的数据丢失.所以采取每条存入的方式 ...

  3. c#devexpres窗体划分 以及panelcontrol 相关操作

    想模仿flashfxp  做一个svn上传的客户端 左侧为本地目录,右侧为svn服务器目录 准备用devexpress 的 控件实现,顺便练习一下devexpress 相关使用. 1:要实现菜单栏工具 ...

  4. PYthon end

    关键字end可以用于将结果输出到同一行,或者在输出的末尾添加不同的字符. # -*- coding:utf-8 -*- count = 1 while count <=5: i=1 while ...

  5. redis 数据类型为list命令整理以及示例

    常用来制作队列,当然lpush+rpop也能做栈 #将RPUSH RPUSHX LPUSH LPUSHX一并介绍(具体介绍RPUSH和RPUSHX,因为其实就是插入的方向的区别) RPUSH key ...

  6. 关于redis和memcached的一些想法

    看了redis和memcached,想到自己前几年以前会把内存分配及调用和程序写在一起.确实是不合理的.这样的话,主进程就会越来越大,而且模块也不是完全独立.不能做到松耦合. 实质就是把内存的读写I/ ...

  7. [Python] 代码中有中文注释会报错

    原因 如果文件里有非ASCII字符,需要在第一行或第二行指定编码声明. 解决方法 在第一行或是第二行加入这么一句# -- coding: utf-8 -- ASCII知识普及: ASCII(Ameri ...

  8. 爬虫初窥day2:正则

    正则在线测试 http://tool.oschina.net/regex https://www.regexpal.com/ http://tool.chinaz.com/regex exp1:筛选所 ...

  9. 专访UI中国认证设计师卤大湿 | 一位UI大师关于UI设计的思考

    现如今,设计师可以说是一个自带光环的Title,很多深藏不漏的UI设计师们都在以自己的方式为产品设计做出贡献,卤大湿便是这其中之一. 精分青年卤大湿,这个在UI中国上是张酷酷的鲁迅头像的UI设计师,是 ...

  10. mysql如何查看自己数据库文件所在的位置

    mysql如何查看自己数据库文件所在的位置 C:\Program Files\MySQL\MySQL Server 5.5 mysql数据库 方法/步骤     第1步: 打开mysqml文件夹,显示 ...