POJ
来源:互联网 发布:os x 怎么恢复mac系统 编辑:程序博客网 时间:2024/05/17 05:09
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
分析:
代码如下:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int maxn = 1000;struct Cost{ int start, end, eff;}cost[maxn];int dp[maxn];//dp[i]为从i开始到N结束产奶最多数 int N,M,R;int cmp(const Cost &a, const Cost &b){ if(a.start<b.start) return 1; else if(a.start == b.start && a.end < b.end) return 1; else return 0;}int main(){ memset(cost, 0, sizeof(cost)); scanf("%d%d%d",&N,&M,&R); for(int i=0; i<M; i++) { scanf("%d%d%d",&cost[i].start, &cost[i].end, &cost[i].eff); cost[i].end += R; } sort(cost, cost+M, cmp); for(int i=M-1; i>=0; i--) { dp[i] = cost[i].eff; for(int j=i+1; j<M; j++) { if(cost[j].start >= cost[i].end) { dp[i] = max(dp[i], dp[j]+cost[i].eff); } } } int maxx=0; for(int i=0; i<M; i++) { maxx = max(maxx, dp[i]); } printf("%d\n",maxx); return 0;}
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- Nginx 基础 总结
- hdu2102 A计划 广搜
- sqlserver存储过程输出参数
- 程序和进程的区别
- Thinkphp3.23下实现文件下载功能
- POJ
- tensorflow总结帖
- Linux--进程间通信-共享内存-信号量
- 红与黑-dfs
- 去除<span style="white-space:normal;">等字符
- 设计模式之策略模式
- eclipse自动提示设置
- js设置a标签href不跳转 禁止跳转
- Let's Encrypt: 为CentOS/RHEL 7下的nginx安装https支持-具体案例