[USACO07NOV]挤奶的时间Milking Time

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=0; char c=getchar();
    while(!isdigit(c)) c=getchar();
    while(isdigit(c)) { x=x*10+c-‘0‘; 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=1;i<=m;++i) read(e[i].l),read(e[i].r),read(e[i].w);
    sort(e+1,e+m+1,cmp);
    for(int i=1;i<=m;++i)
    {
        dp[i]=max(dp[i-1],e[i].w);
        for(int j=1;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
时间: 2024-11-12 20:18:35

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

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

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

USACO milking cows

题意是给你一个工人挤奶的时间, 然后让你求出最长连续工作时间和最长连续不工作时间..离散化后直接扫一遍即可: /* ID: m1500293 LANG: C++ PROG: milk2 */ #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int n; int x[2*5000 + 100]; int num; struct Person { int x, y;

USACO Section1.2 Milking Cows 解题报告

milk2解题报告 —— icedream61 博客园(转载请注明出处)------------------------------------------------------------------------------------------------------------------------------------------------[题目] N个农民,每个农民从L[i]到R[i]时间给奶牛挤奶.问最长的一直有人挤奶的时间,和最长的没有人挤奶的时间.[数据范围] 1<=N

POJ 3190 Stall Reservations(贪心+优先队列优化)

Description Oh those picky N (1 <= N <= 50,000) cows! They are so picky that each one will only be milked over some precise time interval A..B (1 <= A <= B <= 1,000,000), which includes both times A and B. Obviously, FJ must create a reserv

洛谷P3093 [USACO13DEC]牛奶调度Milk Scheduling

题目描述 Farmer John has N cows that need to be milked (1 <= N <= 10,000), each of which takes only one unit of time to milk. Being impatient animals, some cows will refuse to be milked if Farmer John waits too long to milk them. More specifically, cow

POJ_3616_Milking_Time

描述 http://poj.org/problem?id=3616 给奶牛挤奶,共m次可以挤,给出每次开始挤奶的时间st,结束挤奶的时间ed,还有挤奶的量ef,每次挤完奶要休息r时间,问最大挤奶量. 分析 对于每一次挤奶,结束时间+=休息时间r. 先把m次挤奶按照开始时间排个序,用f[i]表示挤完第i个时间段的奶以后的最大挤奶量,那么有: f[i]=max(f[i],f[j]+(第i次挤奶.ef)) (1<=j<i&&(第j次挤奶).ed<=(第i次挤奶).st). 注意

USACO翻译:USACO 2013 DEC Silver三题

USACO 2013 DEC SILVER 一.题目概览 中文题目名称 挤奶调度 栅栏油漆 奶牛排队 英文题目名称 msched paint lineup 可执行文件名 msched paint lineup 输入文件名 msched.in paint.in lineup.in 输出文件名 msched.out paint.out lineup.out 每个测试点时限 1秒 1秒 1秒 测试点数目 10 10 10 每个测试点分值 10 10 10 比较方式 全文比较 全文比较 全文比较 二.运

dp入门 专题记录 2017-7-26

POJ3176-Cow Bowling 题目大意:现有n行数,以金字塔的形式排列,即第一行一个数字,第二行2个数字,依次类推,现在需要找一条从第一层到第n层的路线,使得该路线上的所有点的权值和最大 思路:根据分析可以得出状态转移方程:dp[i][j]=max(dp[i-1][j],dp[i-1][j-1]),dp[i][j]表示以第i行第j个位置作为终点的的线路中的最大权值. #include <iostream> using namespace std; const int N = 360;

【贪心】POJ3190-Stall Reservations

[题目大意] 给出每个奶牛挤奶的时间,同一时间同一畜栏内不会有两头奶牛挤奶,问至少要多少个畜栏. [思路] 将奶牛按照挤奶开始的时间进行升序排序,再用一个小顶堆维护每一个畜栏当前的挤奶结束时间.对于当前的奶牛,如果所有畜栏最小的结束时间都大于它的开始时间,则新开一个畜栏,将结束时间设为当前奶牛的结束时间,加入优先队列:如果能够用结束时间最小的畜栏了,则将该畜栏的结束时间更新为当前奶牛的结束时间. 最后按照输入顺序输出结果. 1 #include<iostream> 2 #include<