博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 3616 Milking Time
阅读量:5281 次
发布时间:2019-06-14

本文共 2191 字,大约阅读时间需要 7 分钟。

Milking Time
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 3607   Accepted: 1533

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

 

动态规划问题,用一个数组dp[i]记录到第i小时最大的产奶量

先将所有牛的产奶时间按结束时间由小到大排序

然后将i从0到n遍历递推一遍,每次先将dp[i]初始化为dp[i-1],然后遍历所有结束时间与i相等的奶牛

  dp[i]=max(dp[i],dp[time[t].start_hour-r]+time[t].eff)

注意time[t].start_hour-r<0时,递推式是这样的:

  dp[i]=max(dp[i],time[t].eff)

 

1 #include
2 #include
3 #include
4 #include
5 6 using namespace std; 7 8 typedef struct 9 {10 int start_hour;11 int end_hour;12 int eff;13 } INTERVAL;14 15 int n,m,r;16 int dp[1000010];17 INTERVAL time[1010];18 19 bool cmp(INTERVAL a,INTERVAL b)20 {21 return a.end_hour
[C++]

 

转载于:https://www.cnblogs.com/lzj-0218/p/3273323.html

你可能感兴趣的文章
IT人生的价值和意义 感觉真的有了
查看>>
Linux命令之df
查看>>
JS DOM对象
查看>>
python正则表达式
查看>>
OGR – Merging Multiple SHP files
查看>>
创业公司该不该被收购?(转)
查看>>
sqlserver 行转列、列转行[转]
查看>>
【IScroll深入学习】解决IScroll疑难杂症
查看>>
python 数据类型
查看>>
108-PHP类成员protected和private成员属性不能被查看数值
查看>>
ajax post data 获取不到数据,注意contentType
查看>>
css控制height充满浏览器视口
查看>>
Linux 系统目录结构
查看>>
servlet中 getRealPath deprecated(被废弃)
查看>>
招聘,项目管理相关
查看>>
UIScreen的scale属性
查看>>
Oracle Scheduler - Postponed job
查看>>
Arduino编程器 USBasp USBtinyISP FT232-ISP 对比 区别
查看>>
高频焊台源码,改进版V2
查看>>
宝塔面板安装的mysql5.5用命令行kill -9后启动不了
查看>>