POJ-3616 Milking Time ( DP )
2016-05-01 14:12
453 查看
题目链接: http://poj.org/problem?id=3616
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
Sample Output
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 2 1 2 8 10 12 19 3 6 24 7 10 31
Sample Output
43 题目大意 有一头奶牛,它有m个工作时间段,每个工作时间可以产一定量的奶,但是它每次工作后都需要休息时间r,求奶牛产奶的最大值 水题 对奶牛工作时间段按开始时间升序排序后,简单DP即可,直接放代码,状态转移方程就不写了
#include<iostream> #include<cstring> #include<cmath> #include<algorithm> using namespace std; class Node{ public: int begin, end, eff; }work[1005]; bool cmp( Node a, Node b ){ return a.begin < b.begin; } int dp[1005]; int main(){ ios::sync_with_stdio( false ); int n, m, r; while( cin >> n >> m >> r ){ for( int i = 1; i <= m; i++ ) cin >> work[i].begin >> work[i].end >> work[i].eff; sort( work + 1, work + m + 1, cmp );\ work[0].begin = work[0].end = work[0].eff; dp[0] = 0; int maxi; for( int i = 1; i <= m; i++ ){ maxi = 0; for( int j = 0; j < i; j++ ){ if( work[i].begin >= work[j].end + r && dp[j] > dp[maxi] ) maxi = j; } dp[i] = dp[maxi] + work[i].eff; } int ans = 0; for( int i = 1; i <= m; i++ ) ans = max( ans, dp[i] ); cout << ans << endl; } return 0; }
相关文章推荐
- opengl学习笔记
- 1000: A+B Problem
- Tiny Web服务器代码分析
- leetcode——116—— Populating Next Right Pointers in Each Node
- Nginx源码分析-核心模块剖析及常见问题
- 334. Increasing Triplet Subsequence
- 2016 UESTC Training for Data Structures C - 卿学姐与诡异村庄 CDOJ 1328 并查集
- 2016 UESTC Training for Data Structures B - 卿学姐与基本法 CDOJ 1325 线段树+离散化
- Centos 6.5 Nginx Web服务器
- HDU-1690-Bus System
- 【LeetCode】Lowest Common Ancestor of a Binary Search Tree 解题报告
- [leetcode] 241. Different Ways to Add Parentheses 解题报告
- 新的开始。
- 正确实现用spring扫描自定义的annotation
- 自我学习
- 2016 UESTC Training for Data Structures A - 卿学姐与公主 CDOJ 1324 线段树
- Gradle DSL method not found android()解决方法
- Java transient关键字的理解
- ActiveRecord 模式
- 2.首先对box2d 的几个重要文件夹里面的内容进行解释