poj3616
来源:互联网 发布:rgb颜色渐变算法 c 编辑:程序博客网 时间:2024/05/29 09:31
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
#include<iostream>#include<string.h>#include<algorithm>#include<cstdio>using namespace std;struct node{int st;int en;int co;};int dp[1050];bool cmp(node x,node y){ return x.en<y.en;}int main(){node ans[10000];int n,m,r;while(cin>>n>>m>>r){for(int i=0;i<m;i++){scanf("%d%d%d",&ans[i].st,&ans[i].en,&ans[i].co);ans[i].en+=r;} //int stx,enx;memset(dp,0,sizeof(dp));sort(ans,ans+m,cmp); for(int i=0;i<m;i++){ dp[i]=ans[i].co; for(int j=0;j<i;j++){ if(ans[j].en<=ans[i].st){ dp[i]=max(dp[i],dp[j]+ans[i].co);//记录每个字段的和 等最后来找出最大就行了。}}}cout<<*max_element(dp, dp + m)<<endl;//找出最大值}}
- poj3616
- poj3616
- POJ3616
- poj3616
- poj3616
- poj3616
- poj3616 dp
- poj3616 dp
- poj3616(LIS)
- POJ3616 MILKING TIME
- poj3616 Milking Time
- POJ3616 Milking Time 【DP】
- POJ3616 简单DP
- POJ3616---Milking Time
- poj3616 解题报告
- POJ3616:Milking Time
- poj3616 动态规划
- poj3616 Milking time
- CMake的简单例子
- 王道计算机网络--3.6局域网
- C++鸡兔同笼问题(做对了有奖品哦!)(五天后发解答)
- mocha设置延时启动/等待(setTimeout)
- 微信支付开发V3版
- poj3616
- C++ 图像边界扩充函数copyMakeBorder
- 用两个栈实现队列
- JVM内存分配策略
- 最小的K个数:二种思路:快排的精髓-----最大堆
- 未来12个趋势
- SAP采购申请订货数量与未清数量错误
- JavaScript最全编码规范
- 对于jsp操作mysql数据库在页面不显示的问题