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

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

                      Milking Time
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 5743   Accepted: 2401

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: NM, 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

Source

 
 
 
 
题意:有一只牛,他在0~N的时间内可以产牛奶,现在有M个区间,你可以指定这M个区间的任意个区间让他去产牛奶,给出这M个区间的开始时间,结束时间,还有在这个区间的时间可以产的牛奶的量。
有个条件,就是你给他指定的产牛奶的区间每2个之间至少要有R的时间让他休息。
现在问怎么指定区间让他去产牛奶,可以获得最大的牛奶。
输出最大的牛奶。
 
基础DP
本质:最长上升子序列。
 
先把区间排序
设dp[i]表示以第i个区间作为让他产牛奶的最后一个区间,可以获得的最大的牛奶量。
 
 
1 #include
2 #include
3 #include
4 5 using namespace std; 6 7 const int maxM=1005; 8 9 long long dp[maxM];10 struct Node11 {12 int u,v;13 long long w;14 }node[maxM];15 16 bool cmp(Node a,Node b)17 {18 if(a.u==b.u)19 return a.v
T||node[i].v>T)38 break;39 dp[i]=node[i].w;40 for(int j=0;j
dp[i])43 dp[i]=dp[j]+node[i].w;44 }45 }46 47 long long ans=-1;48 for(int i=0;i
ans)50 ans=dp[i];51 printf("%lld\n",ans);52 }53 return 0;54 }
View Code

 

 
 
 
 

转载于:https://www.cnblogs.com/-maybe/p/4601141.html

你可能感兴趣的文章
xml=>数组
查看>>
Python全栈开发
查看>>
HDU 5171 GTY's birthday gift 矩阵快速幂
查看>>
原生JS获取url汇总
查看>>
设置session生存时间问题
查看>>
CentOS 添加新的硬盘之后不停机操作
查看>>
3.1 一个简单的Java应用程序
查看>>
函数笔记
查看>>
正则表达式补充
查看>>
Vue中全局和按需引入Echarts
查看>>
框架目录
查看>>
MSSql技巧之快速得到表的记录总数
查看>>
RDIFramework.NET — 基于.NET的快速信息化系统开发框架 - 5.3 数据库连接管理模块...
查看>>
Webservice测试从头来
查看>>
no such table
查看>>
解决 An invalid domain was specified for this cookie
查看>>
JSON新特性
查看>>
微信支付choosewxpay:fail
查看>>
简单的 JSON 对象进行深拷贝最简单的方法
查看>>
Java method Exception throw with return instance.
查看>>