https://daniu.luogu.org/problemnew/show/2889

按右端点从小到大排序后DP

dp[i] 到第i个时间段的最大产奶量

不能按左端点排序,第i段由第j段更新时,第j段可能没挤奶,i,j都处于第k(k<j)段之后的休息时间

#include<cstdio>
#include<iostream>
#include<algorithm> using namespace std; #define N 1001 int dp[N]; struct node
{
int l,r,w;
}e[N]; void read(int &x)
{
x=; char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
} bool cmp(node p,node q)
{
return p.r<q.r;
} int main()
{
int n,m,R;
read(n); read(m); read(R);
for(int i=;i<=m;++i) read(e[i].l),read(e[i].r),read(e[i].w);
sort(e+,e+m+,cmp);
for(int i=;i<=m;++i)
{
dp[i]=max(dp[i-],e[i].w);
for(int j=;j<i;++j)
if(e[j].r+R<=e[i].l)
dp[i]=max(dp[j]+e[i].w,dp[i]);
}
cout<<dp[m];
}

题目描述

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.

奶牛Bessie在0~N时间段产奶。农夫约翰有M个时间段可以挤奶,时间段f,t内Bessie能挤到的牛奶量e。奶牛产奶后需要休息R小时才能继续下一次产奶,求Bessie最大的挤奶量。

输入输出格式

输入格式:

  • 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

输出格式:

  • Line 1: The maximum number of gallons of milk that Bessie can product in the N hours

输入输出样例

输入样例#1: 复制

12 4 2
1 2 8
10 12 19
3 6 24
7 10 31
输出样例#1: 复制

43

[USACO07NOV]挤奶的时间Milking Time的更多相关文章

  1. P2889 [USACO07NOV]挤奶的时间Milking Time

    P2889 [USACO07NOV]挤奶的时间Milking Time 奶牛Bessie在0~N时间段产奶.农夫约翰有M个时间段可以挤奶,时间段f,t内Bessie能挤到的牛奶量e.奶牛产奶后需要休息 ...

  2. bzoj1642 / P2889 [USACO07NOV]挤奶的时间Milking Time

    P2889 [USACO07NOV]挤奶的时间Milking Time 普通的dp 休息时间R其实就是把结束时间后移R个单位而已.但是终点也需要后移R位到n+R. 每个时间段按起始时间排序,蓝后跑一遍 ...

  3. 【题解】Luogu P2889 [USACO07NOV]挤奶的时间Milking Time

    Luogu P2889 [USACO07NOV]挤奶的时间Milking Time 题目描述 传送门Bessie is such a hard-working cow. In fact, she is ...

  4. 题解 最优的挤奶方案(Optimal Milking)

    最优的挤奶方案(Optimal Milking) 时间限制: 1 Sec  内存限制: 128 MB 题目描述 农场主 John 将他的 K(1≤K≤30)个挤奶器运到牧场,在那里有 C(1≤C≤20 ...

  5. dp专题练习

    顺便开另外一篇放一些学过的各种dp dp总结:https://www.cnblogs.com/henry-1202/p/9194066.html 开坑先放15道题,后面慢慢补 目标50道题啦~~,目前 ...

  6. Milking Cows 挤牛奶

    1.2.1 Milking Cows 挤牛奶 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 554  Solved: 108[Submit][Status ...

  7. 【POJ - 3616】Milking Time(动态规划)

    Milking Time 直接翻译了 Descriptions 贝茜是一个勤劳的牛.事实上,她如此​​专注于最大化她的生产力,于是她决定安排下一个N(1≤N≤1,000,000)小时(方便地标记为0. ...

  8. USACO Section1.2 Milking Cows 解题报告

    milk2解题报告 —— icedream61 博客园(转载请注明出处)---------------------------------------------------------------- ...

  9. poj 3616 Milking Time (基础dp)

    题目链接 http://poj.org/problem?id=3616 题意:在一个农场里,在长度为N个时间可以挤奶,但只能挤M次,且每挤一次就要休息t分钟: 接下来给m组数据表示挤奶的时间与奶量求最 ...

随机推荐

  1. 对WEB url 发送POST请求

    package com.excellence.spark; import java.util.List; import com.excellence.spark.test.test; import c ...

  2. 用windbg检查.NET线程池设置

    比如我们在machine.config中进行了这样的设置(8核CPU): <processModel maxWorkerThreads="100" maxIoThreads= ...

  3. utf-8编码的中文看成2个字符,其他数字字符看成一个字符

    方法一:使用正则表达式,代码如下: function getByteLen(val) {            var len = 0;            for (var i = 0; i &l ...

  4. DTCping 的简单使用与排错

    1. 工具下载路径 https://support.microsoft.com/zh-cn/help/918331/how-to-troubleshoot-connectivity-issues-in ...

  5. 1使用 vue-cli 搭建项目(cp)

    http://www.cnblogs.com/wisewrong/p/6255817.html(copy:web) https://zhuanlan.zhihu.com/p/26183652(也很好) ...

  6. SpannableString的基本用法

    原文地址:http://www.cnblogs.com/kross/p/3645594.html 以前一直好奇QQ的输入框里面是如何出现表情的,今天看了下这个,心中发出“原来是这样啊”的感叹. 通常情 ...

  7. 回车”(carriage return)和”换行”(line feed)的区别和来历-(附:ASCII表)

    这两天研究小票打印机编程手册,遇到这样一个问题:     LF,即Line Feed,中文意思“换行”:CR,即Carriage Return,中文意思“回车”.但是我们通常把这两个混为一谈.既然设置 ...

  8. Common Substrings POJ - 3415(长度不小于k的公共子串的个数)

    题意: 给定两个字符串A 和 B, 求长度不小于 k 的公共子串的个数(可以相同) 分两部分求和sa[i-1] > len1  sa[i] < len1  和  sa[i-1] < ...

  9. shiro异常类型

    <!-- 身份认证异常 --> <!-- 身份令牌异常,不支持的身份令牌 --> org.apache.shiro.authc.pam.UnsupportedTokenExce ...

  10. UIScrollView浏览一组图片,且图片与图片之间有间隔

    ---恢复内容开始--- UIScrollView是可以浏览一组view的,只要将其属性 pagingEnabled设置为true就可以了.具体过程是这样的, 1:将一组图片按照从左到右的顺序添加到U ...