Poj 3616 Milking Time【dp】
来源:互联网 发布:织梦 添加视频不播放 编辑:程序博客网 时间:2024/04/29 11:55
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 efficiencyi
Output
* Line 1: The maximum number of gallons of milk that Bessie can product in the N hours
Sample Input
12 4 21 2 810 12 193 6 247 10 31
Sample Output
43
Source
题意:
有个人的奶牛要产奶,给出这个人在某些时间段的能够采集的量,且某一时间段内不允许中断,问这个人最多能采集多少牛奶
动态规划不好做,一直找递推式,就是不知道到底如何下手,后来看了大神的题解,也是理解的迷迷糊糊的,真的是不会做.......
本题的dp[i]表示第 i 个时间段时一共能采集的量,对每个时间段都只统计它后边的时间段的最值,这样避免了很多的时间段的交叉的复杂的处理。
/*http://blog.csdn.net/liuke19950717*/#include<cstdio>#include<cstring>#include<algorithm>using namespace std;struct node{ int bg,ed,milk;}x[1005];int cmp(node a,node b){ if(a.ed==b.ed) { return a.bg<b.bg; } return a.ed<b.ed;}int slove(int n,int m,int r){ int dp[1005]={0}; sort(x,x+m,cmp); for(int i=0;i<m;++i) { dp[i]=x[i].milk;}//dp[i] 表示第 i 次工作时,挤奶的最大量 for(int i=0;i<m;++i)// { for(int j=i+1;j<m;++j) { if(x[i].ed+r<=x[j].bg) { dp[j]=max(dp[j],dp[i]+x[j].milk);} } } int ans=0; for(int i=0;i<m;++i) { ans=max(ans,dp[i]);} return ans;}int main(){ int n,m,r; while(~scanf("%d%d%d",&n,&m,&r)) { for(int i=0;i<m;++i) { scanf("%d%d%d",&x[i].bg,&x[i].ed,&x[i].milk); } printf("%d\n",slove(n,m,r)); } return 0;}
- poj 3616 Milking Time DP
- POJ 3616 Milking Time DP
- poj-3616 Milking Time 【DP】
- poj 3616 Milking Time DP
- DP-POJ-3616-Milking Time
- poj 3616 Milking Time 【dp】
- [POJ 3616]Milking Time[DP]
- Poj 3616 Milking Time【dp】
- POJ - 3616 Milking Time(Dp)
- POJ 3616 Milking Time (DP)
- poj 3616 Milking Time (DP)
- [ poj 3616] Milking Time [ DP ]
- POJ 3616 Milking Time(简单DP)
- POJ 3616-Milking Time (基础DP)
- POJ 3616 Milking Time DP题解
- POJ 3616 Milking Time DP题解
- poj 3616 Milking Time dp+树状数组
- POJ 3616 Milking Time (dp)
- 管闲事的小明
- 【三层】——C#与VB.NET各显神通
- URI数据存储初解
- CodeForces-626A-Robot Sequence
- 最大矩阵和 HDU1081 & NYOJ 104
- Poj 3616 Milking Time【dp】
- c#接口
- ImageView 常用属性的分析
- 希尔排序
- 第四次上机实践项目-项目一-三角形类锥形-(1)
- 第五周上机实践项目——项目4-长方柱类
- 关于placeholder的小tip
- NOI2009植物大战僵尸题解
- x & (x-1)的意义