Luogu P2889 [USACO07NOV]挤奶的时间Milking Time

题目描述

传送门
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: 复制

  1. 12 4 2
  2. 1 2 8
  3. 10 12 19
  4. 3 6 24
  5. 7 10 31

输出样例#1: 复制

  1. 43

思路

  • 可以发现从挤奶开始一直到休息完是一个整体,都不能进行转移

  • 所以直接将挤奶时间看作一个整体变成 $time+r$ 进行转移就可以了

  • $f[i]$表示第i分钟的最优收益,$time[i]$ 为这次挤奶的持续时间, $w[i]$ 是这次挤奶的收益

  • 转移方程 $f[i+time[i]+r]=max(f[i+time[i]+r],f[i]+w[i])$

代码

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<cstring>
  5. #define re register int
  6. using namespace std;
  7. int read(){
  8. int x=0,w=1; char ch=getchar();
  9. while(ch!='-'&&(ch<'0'&&ch>'9')) ch=getchar();
  10. if(ch=='-') w=-1,ch=getchar();
  11. while(ch>='0'&&ch<='9') x=x*10+ch-48,ch=getchar();
  12. return x*w;
  13. }
  14. int n,m,r,f[2000005],y;
  15. bool tmp[2000005];
  16. struct data{
  17. int st,tim,w;
  18. }cow[1005];
  19. bool cmp(data cow,data b){
  20. return cow.st<b.st;
  21. }
  22. int main(){
  23. //freopen("p2889.in","r",stdin);
  24. //freopen("p2889.out","w",stdout);
  25. n=read(),m=read(),r=read();
  26. n=n+r+10;
  27. for(re i=1;i<=m;i++){
  28. cow[i].st=read(),y=read(),cow[i].w=read();
  29. cow[i].tim=y-cow[i].st+r;
  30. tmp[cow[i].st]=1;
  31. }
  32. sort(cow+1,cow+1+m,cmp);
  33. int j=1;
  34. for(re i=0;i<=n;i++){
  35. f[i]=max(f[i],f[i-1]);
  36. if(tmp[i]){
  37. for(;cow[j].st==i;j++){
  38. f[i+cow[j].tim]=max(f[i+cow[j].tim],f[i]+cow[j].w);
  39. }
  40. }
  41. }
  42. printf("%d\n",f[n]);
  43. return 0;
  44. }

【题解】Luogu P2889 [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. [USACO07NOV]挤奶的时间Milking Time

    https://daniu.luogu.org/problemnew/show/2889 按右端点从小到大排序后DP dp[i] 到第i个时间段的最大产奶量 不能按左端点排序,第i段由第j段更新时,第 ...

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

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

  5. [题解] Luogu P5446 [THUPC2018]绿绿和串串

    [题解] Luogu P5446 [THUPC2018]绿绿和串串 ·题目大意 定义一个翻转操作\(f(S_n)\),表示对于一个字符串\(S_n\), 有\(f(S)= \{S_1,S_2,..., ...

  6. 【题解】Luogu P1204 [USACO1.2]挤牛奶Milking Cows

    原题传送门:P1204 [USACO1.2]挤牛奶Milking Cows 实际是道很弱智的题目qaq 但窝还是觉得用珂朵莉树写会++rp(窝都初二了,还要考pj) 前置芝士:珂朵莉树 窝博客里对珂朵 ...

  7. 题解 Luogu P2499: [SDOI2012]象棋

    关于这道题, 我们可以发现移动顺序不会改变答案, 具体来说, 我们有以下引理成立: 对于一个移动过程中的任意一个移动, 若其到达的位置上有一个棋子, 则该方案要么不能将所有棋子移动到最终位置, 要么可 ...

  8. 题解 luogu P1144 【最短路计数】

    本蒟蒻也来发一次题解第一篇请见谅 这个题有几个要点 1.无向无权图,建图的时候别忘记建来回的有向边[因此WA掉1次 2.无权嘛,那么边长建成1就好了2333333 3.最短路采用迪杰斯特拉(别忘用堆优 ...

  9. [LUOGU] P2886 [USACO07NOV]牛继电器Cow Relays

    https://www.luogu.org/problemnew/show/P2886 给定无向连通图,求经过k条边,s到t的最短路 Floyd形式的矩阵乘法,同样满足结合律,所以可以进行快速幂. 离 ...

随机推荐

  1. 有趣的css—简单的下雨效果

    简单的下雨效果 前言 最近在b站上看到一个下雨效果的视频,感觉思路很清奇,我也按照自己的思路做了一个简单的下雨效果. 由于我制作GIF图片的工具最多只支持制作33FPS的GIF图,所以看起来可能有一点 ...

  2. 测试的V模型和W模型

    V模型 :后测试 优点: 1.每一阶段都清晰明了,便于把控开发的每一个过程. 2.既包含了单元测试又包含了系统测试 缺点: 1.测试介入的比较晚,所以开发前期的缺陷无从修改. 2.开发和测试串行. W ...

  3. 用 edgeadm 一键安装边缘 K8s 集群和原生 K8s 集群

    背景 目前,很多边缘计算容器开源项目在使用上均存在一个默认的前提:用户需要提前准备一个标准的或者特定工具搭建的 Kubernetes 集群,然后再通过特定工具或者其他方式在集群中部署相应组件来体验边缘 ...

  4. 数据库和SQL概述

    一.数据库的概念 1.DB 数据库(database):存储数据的"仓库".它保存了一系列有组织的数据. 2.DBMS 数据库管理系统(Database Management Sy ...

  5. CF1444A Division 求质因数的方法

    2020.12.20 求质因数的方法 CF1444A Division #include<bits/stdc++.h> #define ll long long #define fp(i, ...

  6. Nifi:初识nifi

    写在前面: 第一次接触这一系统的时候,只有github上的一坨源码和官方的英文文档,用起来只能说是一步一个坑,一踩一个脚印,现在回想那段血泪史,只想 ***,现在用起来算是有了一些经验和总结,这里就做 ...

  7. 19 常用API

    API 什么是API? API (Application Programming Interface) :应用程序编程接口 简单来说:就是Java帮我们已经写好的一些方法,我们直接拿过来用就可以了 1 ...

  8. TCP 中的两个细节点

    TCP 超时和重传 没有永远不出错误的通信,这句话表明着不管外部条件多么完备,永远都会有出错的可能.所以,在 TCP 的正常通信过程中,也会出现错误,这种错误可能是由于数据包丢失引起的,也可能是由于数 ...

  9. [bug] CM / CDH 主机运行状态不良情况

    参考 https://blog.csdn.net/fhfkv8644/article/details/82383196 无法发出查询:Host Monitor 未运行 https://blog.csd ...

  10. BRAM 和 DRAM 区别

    转载: BRAM和DRAM的区别 Xilinx的FPGA开发板可以直接调用RAM,其中包括了BRAM和DRAM.经过网上查找资料发现,这两者的区别在于: 选择distributed memory ge ...