POJ-3616
Milking Time
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10434 Accepted: 4378 Description
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 efficiencyiOutput
* Line 1: The maximum number of gallons of milk that Bessie can product in the N hours
Sample Input
12 4 2
1 2 8
10 12 19
3 6 24
7 10 31Sample Output
43
题意:
在n时间内,有m个时间段,每段时间的值为v,每一段结束以后要休息r时间才能继续。
求n时间内v的最大值。
先按s从小到大排序,而后求出每一项前的最大值,则dp[i]=maxx+dp[j]。
AC代码:
//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; const int MAXN=;
int dp[MAXN]; struct node{
int s,e,v;
}a[MAXN]; int cmp(node x, node y){
return x.s<y.s;
} int main(){
ios::sync_with_stdio(false);
int n,m,r;
while(cin>>n>>m>>r){
for(int i=;i<m;i++){
cin>>a[i].s>>a[i].e>>a[i].v;
}
sort(a,a+m,cmp);
int res=;
for(int i=;i<m;i++){
int maxx=;
for(int j=;j<i;j++){
if(a[j].e+r<=a[i].s&&maxx<dp[j])
maxx=dp[j];
}
dp[i]=maxx+a[i].v;
res=max(res,dp[i]);
}
cout<<res<<endl;
}
return ;
}
POJ-3616的更多相关文章
- POJ 3616 Milking Time (排序+dp)
题目链接:http://poj.org/problem?id=3616 有头牛产奶n小时(n<=1000000),但必须在m个时间段内取奶,给定每个时间段的起始时间和结束时间以及取奶质量 且两次 ...
- POJ 3616 Milking Time(最大递增子序列变形)
题目链接:http://poj.org/problem?id=3616 题目大意:给你时间N,还有M个区间每个区间a[i]都有开始时间.结束时间.生产效率(时间都不超过N),只能在给出的时间段内生产, ...
- POJ 3616 Milking Time(加掩饰的LIS)
传送门: http://poj.org/problem?id=3616 Milking Time Time Limit: 1000MS Memory Limit: 65536K Total Sub ...
- poj 3616 Milking Time (基础dp)
题目链接 http://poj.org/problem?id=3616 题意:在一个农场里,在长度为N个时间可以挤奶,但只能挤M次,且每挤一次就要休息t分钟: 接下来给m组数据表示挤奶的时间与奶量求最 ...
- DP:Miking Time(POJ 3616)
2015-09-21 奶牛挤奶 题目大意就是这只Bessie的牛产奶很勤奋,某农民有一个时刻表,在N时间内分成M个时间段,每个时间段Bessie会一直产奶,然后有一定的效益,并且Bessie产奶后要休 ...
- poj 3616 Milking Time
Milking ...
- POJ 3616 DP
题意:给你N的时间,M的工作时间段,每个时间段有一个权重,还有一个R,每次完成一个工作需要休息R,问最后在时间N内,最大权重是多少. 思路:很简单的DP,首先对区间的右坐标进行排序,然后直接转移方程就 ...
- POJ 3616 Milking Time 简单DP
题意:奶牛Bessie在0~N时间段产奶.农夫约翰有M个时间段可以挤奶,时间段f,t内Bessie能挤到的牛奶量e.奶牛产奶后需要休息R小时才能继续下一次产奶,求Bessie最大的挤奶量. 详见代码 ...
- POJ 3616 Milking Time (字符串DP)
题意:找元素关于对角线左或右对称的最大矩阵 思路:左右对角线只需要遍历一条就可以了.只要当前点往上遍历和往后遍历一样就可以. #include<iostream> #include< ...
- poj 3616 Milking Time DP
题意:在给予的N个时间里,奶牛Bessie在M个时间段里进行产奶,但是每次产奶后都要休息R个时间 M个时间段里,分别有开始时间start和结束时间end,和该时间段里产奶的效率efficiency 求 ...
随机推荐
- Android-彻底地理解Binder
转自:https://blog.csdn.net/huachao1001 https://blog.csdn.net/huachao1001/article/details/51504469 你是不是 ...
- kafka source type
https://flume.apache.org/FlumeUserGuide.html # example.conf: A single-node Flume configuration # Nam ...
- d3 - bar chart
用 D3.js 做一个简单的柱形图. 做柱形图有很多种方法,比如用 HTML 的 div 标签,或用 svg . 推荐用 SVG 来做各种图形.SVG 意为可缩放矢量图形(Scalable Vecto ...
- BZOJ3878: [Ahoi2014&Jsoi2014]奇怪的计算器
BZOJ3878: [Ahoi2014&Jsoi2014]奇怪的计算器 Description [故事背景] JYY有个奇怪的计算器,有一天这个计算器坏了,JYY希望你能帮助他写 一个程序来模 ...
- 爬虫-【selenium——webElement常用方法】
a)clear——清除元素的内容 driver.find_element_by_id("**").clesr() b)send_keys——在元素上模拟按键输入 driver.fi ...
- tmux基本使用方法
tmux是一款优秀的终端复用软件.tmux采用C/S模型构建,输入tmux命令就相当于开启了一个服务器,此时默认将新建一个会话,然后会话中默认新建一个窗口,窗口中默认新建一个面板. 一个tmux se ...
- git 生成patch和应用patch【转】
本文转载自:http://www.jianshu.com/p/814fb6606734 1.在git源码目录下执行 1.1.两个commit间的修改(包含两个commit) git format-pa ...
- tkinter之canvas(画布)
画布的例子: from tkinter import * root=Tk() root.title('简易绘图') can=Canvas(root,width=400,height=300,bg='# ...
- python之menu
只有主菜单没有二级菜单的例子: from tkinter import * root=Tk() root.wm_title('同济大学财务管理系统') menubar=Menu(root)#指定菜单实 ...
- codeforces 705C C. Thor(模拟)
题目链接: C. Thor time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...