当前位置:网站首页>POJ - 3616 Milking Time(DP+LIS)
POJ - 3616 Milking Time(DP+LIS)
2022-07-07 05:27:00 【WA_自动机】
POJ - 3616 Milking Time
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
43
牛在n时间内产奶,农夫有m段时间可以挤奶,每一段时间有开始点strat,结束点end,和这段时间的挤奶量w。 每一次挤奶后,牛都必须休息r时间。问在最合理的挤奶安排下挤到的最大牛奶量是多少?
首先按照结束时间排序区间,然后按照第i个区间选择与否进行动态规划
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1010;
struct Node
{
int l,r,val;
}a[N];
int dp[N];
bool cmp(Node A,Node B)
{
return A.r<B.r;
}
int main()
{
int n,m,r;cin>>n>>m>>r;
for(int i=1;i<=m;i++)
{
cin>>a[i].l>>a[i].r>>a[i].val;
a[i].r+=r;
}
sort(a+1,a+m+1,cmp);
for(int i=1;i<=m;i++)
{
dp[i]=a[i].val;
for(int j=1;j<i;j++)
if(a[j].r<=a[i].l)
dp[i]=max(dp[i],dp[j]+a[i].val);
}
int ans=0;
for(int i=1;i<=m;i++)
ans=max(ans,dp[i]);
cout<<ans<<endl;
return 0;
}
边栏推荐
- Several ways of lambda used in functions in kotlin (higher-order functions)
- [quick start of Digital IC Verification] 13. SystemVerilog interface and program learning
- Using helm to install rainbow in various kubernetes
- Coquette data completes the cloud native transformation through rainbow to realize offline continuous delivery to customers
- eBPF Cilium实战(2) - 底层网络可观测性
- GFS分布式文件系统
- The use of generics and vararg variable parameters in kotlin
- Automatic upgrading of database structure in rainbow
- 机器人教育在动手实践中的真理
- Domain specific language / DSL in kotlin
猜你喜欢

在 Rainbond 中一键安装高可用 Nacos 集群
![[untitled]](/img/b5/348b1d8b5d34cf10e715522b9871f2.png)
[untitled]

解读创客思维与数学课程的实际运用

在Rainbond中一键部署高可用 EMQX 集群

Splunk子查询模糊匹配csv中字段值为*
![[quick start of Digital IC Verification] 12. Introduction to SystemVerilog testbench (svtb)](/img/dc/a809f2ec5f9e85a02e68c88bdcdb5e.png)
[quick start of Digital IC Verification] 12. Introduction to SystemVerilog testbench (svtb)

Interpreting the practical application of maker thinking and mathematics curriculum

GFS distributed file system

柯基数据通过Rainbond完成云原生改造,实现离线持续交付客户

Leetcode simple question: find the K beauty value of a number
随机推荐
Rsync remote synchronization
2-3查找樹
IP-guard助力能源企业完善终端防泄密措施,保护机密资料安全
Four items that should be included in the management system of integral mall
Openjudge noi 2.1 1752: chicken and rabbit in the same cage
轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
Xcit learning notes
PVTV2--Pyramid Vision TransformerV2学习笔记
The use of generics and vararg variable parameters in kotlin
Rainbow combines neuvector to practice container safety management
【无标题】
Openvscode cloud ide joins rainbow integrated development system
使用 Nocalhost 开发 Rainbond 上的微服务应用
MES系统,是企业生产的必要选择
Open3d ISS key points
【Go ~ 0到1 】 第七天 获取时间戳,时间比较,时间格式转换,Sleep与定时器
Improve the delivery efficiency of enterprise products (1) -- one click installation and upgrade of enterprise applications
Use of out covariance and in inversion in kotlin
Caractéristiques de bisenet
归并排序和非比较排序