poj3136 Milking Time
来源:互联网 发布:c语言基础知识txt下载 编辑:程序博客网 时间:2024/06/06 08:36
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
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
#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>#define INF 0x3f3f3f3fint dp[1000+10];struct abcd{ int start; int end; int eff;}s[1000+10];int cmp(const void *a,const void *b){ return (*(struct abcd *)a).start-(*(struct abcd *)b).start;}int main(){ int m,n,r; int i,j,k,max; while(scanf("%d%d%d",&n,&m,&r)==3) { for(i=0;i<m;i++) scanf("%d%d%d",&s[i].start,&s[i].end,&s[i].eff); qsort(s,m,sizeof(struct abcd),cmp); //for(i=0;i<m;i++) // printf("%d %d %d\n",s[i].start,s[i].end,s[i].eff); memset(dp,0,sizeof(dp)); if(s[0].end<=n) dp[0]=s[0].eff; for(i=1;i<m;i++) { if(s[i].end<=n) max=s[i].eff; for(j=0;j<i;j++) { if(s[i].start>=s[j].end+r&&s[i].end<=n) { if(dp[j]+s[i].eff>max) max=dp[j]+s[i].eff; } } dp[i]=max; } for(i=0,max=0;i<m;i++) { if(dp[i]>max) max=dp[i]; } printf("%d\n",max); } return 0;}
0 0
- poj3136 Milking Time
- Milking Time
- Milking Time
- pku3616 Milking Time
- poj 3616 Milking Time
- Milking Time 简单DP
- POJ 3616 Milking Time
- POJ-3616-Milking Time
- poj 3616 Milking Time
- POJ3616 MILKING TIME
- POJ 3616 Milking Time
- poj3616 Milking Time
- POJ3616 Milking Time 【DP】
- poj 3616 Milking Time
- POJ3616---Milking Time
- Milking Time.(POJ-3616)
- POJ 3616 Milking Time
- POJ 3616 Milking Time
- hdu1078 FatMouse and Cheese
- scala基础与实践上
- POJ-1456 Supermarket (贪心)
- 进程 vs. 线程
- POJ3259-JAVA语言描述-Bellman_Ford算法
- poj3136 Milking Time
- 帧、数据报、数据包的区别和联系
- iOS开发 ☞ 推送通知(Push Notification)
- 【AKOJ】1125小写字母变为大写字母
- adapter总结
- IMF SPARK 源代码发行定制班 预习课程 Spark框架源码的调试 (2) 从master worker main入口进行调试
- hdu2859 Phalanx
- 自动加载下一页
- Bloom Filter - Math deduce