POJ3616--Milking Time(动态规划)
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 思路还是很不对,一开始就没有想到可以直接把间隔加在本次结束时间上。其次,我也想的是对每一小时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(动态规划)的更多相关文章
- 动态规划 POJ3616 Milking Time
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; st ...
- POJ - 3616 Milking Time (动态规划)
Bessie is such a hard-working cow. In fact, she is so focused on maximizing her productivity that sh ...
- poj3616 Milking Time(状态转移方程,类似LIS)
https://vjudge.net/problem/POJ-3616 猛刷简单dp的第一天第二题. 这道题乍一看跟背包很像,不同的在于它是一个区间,背包是定点,试了很久想往背包上套,都没成功. 这题 ...
- D - Milking Time 动态规划
Bessie is such a hard-working cow. In fact, she is so focused on maximizing her productivity that sh ...
- POJ3616 Milking Time —— DP
题目链接:http://poj.org/problem?id=3616 Milking Time Time Limit: 1000MS Memory Limit: 65536K Total Sub ...
- POJ3616 Milking Time【dp】
Description Bessie is such a hard-working cow. In fact, she is so focused on maximizing her producti ...
- poj-3616 Milking Time (区间dp)
http://poj.org/problem?id=3616 bessie是一头工作很努力的奶牛,她很关心自己的产奶量,所以在她安排接下来的n个小时以尽可能提高自己的产奶量. 现在有m个产奶时间,每个 ...
- 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为结尾 ...
- poj3616 Milking Time
思路: dp. 实现: #include <iostream> #include <cstdio> #include <algorithm> using names ...
- 《挑战程序设计竞赛》2.3 动态规划-基础 POJ3176 2229 2385 3616 3280
POJ3176 Cow Bowling 题意 输入一个n层的三角形,第i层有i个数,求从第1层到第n层的所有路线中,权值之和最大的路线. 规定:第i层的某个数只能连线走到第i+1层中与它位置相邻的两个 ...
随机推荐
- js 实现的简易计算器
<!DOCTYPE html><html lang="zh-CN"><head> <!-- <meata charset='utf- ...
- javascript 高级程序设计 七
引言:好几天没有写随笔了,项目有点紧,恰好今天项目遇到了比较大阻塞,就只好来写一篇随笔来压压惊. 1.Date类型 创建一个新的Date:(除了new Date()外) var someDate = ...
- [都是原创]Php simplexml 添加节点
Php simplexml 添加节点 原始代码如下 //================<? //创建xml对象$xml = new SimpleXMLElement('<Messages ...
- 【统一异常处理】@ControllerAdvice + @ExceptionHandler 全局处理 Controller 层异常
1.利用springmvc注解对Controller层异常全局处理 对于与数据库相关的 Spring MVC 项目,我们通常会把 事务 配置在 Service层,当数据库操作失败时让 Service ...
- 2017/2/10:Manven简介与项目管理(入门)
1.Maven工程的创建 2.使用Manven manven配置文件主要集中在 http://m.blog.csdn.net/article/details?id=50316383
- Java中TreeMap的基本操作
TreeSet有四种种构造函数可以初始化 在代码中主要列出了常用的三种: 构造方法摘要 TreeSet() 构造一个新的空 set,该 set 根据其元素的自然顺序进行排序. Tr ...
- python学习 day6 (3月7日)
#__author : 'liuyang' #date : 2019/3/7 0007 a = ['a' , 'b' , 'c'] b = [] print(a is b ) # 空元组 可以 空列表 ...
- 2019.01.22 SCU4444 Travel(最短路+bfs)
传送门 题意简述:给出一张nnn个点的完全图,有mmm条边边权为aaa其余点边权为bbb,问从111到nnn的最短路. 思路:分类讨论一波即可. (1,n)(1,n)(1,n)的边权为aaa,那么只用 ...
- 2018.12.31 bzoj4001: [TJOI2015]概率论(生成函数)
传送门 生成函数好题. 题意简述:求nnn个点的树的叶子数期望值. 思路: 考虑fnf_nfn表示nnn个节点的树的数量. 所以有递推式f0=1,fn=∑i=0n−1fifn−1−i(n>0) ...
- 多项式相关&&生成函数相关&&一些题目(updating...)
文章目录 多项式的运算 多项式的加减法,数乘 多项式乘法 多项式求逆 多项式求导 多项式积分 多项式取对 多项式取exp 多项式开方 多项式的除法/取模 分治FFT 生成函数 相关题目 多项式的运算 ...