poj 3616 Milking Time DP
来源:互联网 发布:非农数据大于预期 编辑:程序博客网 时间:2024/05/16 00:34
Description
Bessie is such a hard-working cow. In fact, she is so focused on maximizing her productivity that she decides to schedule her nextN (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 intervali 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 restR (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 theN 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 theN hours
Sample Input
12 4 21 2 810 12 193 6 247 10 31
Sample Output
43
Source
Source CodeProblem: 3616Memory: 240KTime: 47MSLanguage: C++Result: Accepted Source Code #include <iostream> #include <stdio.h> #include <algorithm> using namespace std; typedef struct{ int start; int end; int value; }Cow; Cow cow[1024]; int dp[1024]; int cmp(const void *a, const void *b) { Cow *_a = (Cow *)a; Cow *_b = (Cow *)b; return _a->start - _b->start; } int Max_value(int a, int b) { return a>b?a:b; } int main() { //freopen("in.txt","r",stdin); int N,M, R; cin >> N >> M >> R; for(int i=0; i < M; i++) { cin >> cow[i].start >>cow[i].end >> cow[i].value; cow[i].end += R; } qsort(cow, M, sizeof(cow[0]), cmp); for(int i=0; i < M; i++) { dp[i] = cow[i].value; for(int j=0; j < i; j++) { if(cow[i].start >= cow[j].end) dp[i]=Max_value(dp[i], dp[j]+cow[i].value); } } cout << *max_element(dp,dp+M) << endl; 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++中的typename
- 【安卓笔记】notification使用
- C++中的using
- ZOJ-1088
- 黑程序员_Java基础加强(中)_JavaBean,注解,泛型_27
- poj 3616 Milking Time DP
- 你的人生是在挑水还是在挖井
- 用Matlab来将分层制造过程中G代码所表示的单层的加工路径显示出来
- poj1008
- android 游戏模拟器源码大全。
- jsp读取properties文件
- poj1046
- 代码审查(code review)的意义
- 希望whatsapp的收购能够引入一种新的商业模式