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_houriN), an ending hour (starting_houri < ending_houriN), 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 ≤ RN) 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

这题问你在那个时间内最多能挤多少奶从后往前面DP
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>

using namespace std;

int N,M,R;
int dp[1000010]={0};

struct st{
    int start;
    int end;
    int eff;
}a[1000010];

bool cmp(st i,st j)
{
    if(i.start<j.start)
        return true;
    return false;
}

int main()
{
    scanf("%d%d%d",&N,&M,&R);
    a[0].start=0;
    a[0].end=0;
    a[0].eff=0;
    for(int i=1;i<=M;i++)
        scanf("%d%d%d",&a[i].start,&a[i].end,&a[i].eff);
    sort(a,a+M+1,cmp);
    dp[a[M].start]=a[M].eff;
    for(int i=M;i>0;i--)
    {
        int s=dp[a[i].start];
        for(int j=a[i].start;j>=a[i-1].start;j--)
            dp[j]=s;
        if(a[i-1].end+R<=a[i].start)
            dp[a[i-1].start]=a[i-1].eff+s;
        else
            dp[a[i-1].start]=max(s,dp[a[i-1].end+R]+a[i-1].eff);
    }
   // printf("\n\n");
   // for(int i=N;i>=0;i--)
    printf("%d",dp[0]);
    //for(int i=1;i<=M;i++)
   //     printf("%d %d %d\n",a[i].start,a[i].end,a[i].eff);
    return 0;
}
时间: 2024-10-16 02:58:41

Milking Time的相关文章

[BZOJ1642][Usaco2007 Nov]Milking Time 挤奶时间

1642: [Usaco2007 Nov]Milking Time 挤奶时间 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 878  Solved: 507 [Submit][Status][Discuss] Description 贝茜是一只非常努力工作的奶牛,她总是专注于提高自己的产量.为了产更多的奶,她预计好了接下来的N (1 ≤ N ≤ 1,000,000)个小时,标记为0..N-1. Farmer John 计划好了 M (1 ≤ M ≤

[2016-03-28][POJ][3616][Milking Time]

时间:2016-03-28 17:27:03 星期一 题目编号:[2016-03-28][POJ][3616][Milking Time] #include <algorithm> #include <cstdio> using namespace std; const int maxm = 1000 + 10; struct Roo{ int l,r,v; bool operator < (const Roo & a)const{ return l < a.l

1642: [Usaco2007 Nov]Milking Time 挤奶时间

1642: [Usaco2007 Nov]Milking Time 挤奶时间 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 582  Solved: 331[Submit][Status] Description 贝茜是一只非常努力工作的奶牛,她总是专注于提高自己的产量.为了产更多的奶,她预计好了接下来的N (1 ≤ N ≤ 1,000,000)个小时,标记为0..N-1. Farmer John 计划好了 M (1 ≤ M ≤ 1,000) 个可以

POJ 2455 Secret Milking Machine(二分+最大流)

POJ 2455 Secret Milking Machine 题目链接 题意:一个无向图,要求有T条不重复道路可以从1走到t,问道路中最大边的最小值可以是多少 思路:二分+最大流,二分长度,连起边,注意是无向图,所以反向边是有容量的,然后源点和1连容量t,n和汇点连容量是t 代码: #include <cstdio> #include <cstring> #include <queue> #include <algorithm> using namespa

POJ 2185 Milking Grid

Milking Grid Time Limit: 3000ms Memory Limit: 65536KB This problem will be judged on PKU. Original ID: 218564-bit integer IO format: %lld      Java class name: Main Every morning when they are milked, the Farmer John's cows form a rectangular grid th

POJ 2112 Optimal Milking

Optimal Milking Time Limit: 2000ms Memory Limit: 30000KB This problem will be judged on PKU. Original ID: 211264-bit integer IO format: %lld      Java class name: Main FJ has moved his K (1 <= K <= 30) milking machines out into the cow pastures amon

poj2185 Milking Grid (最小覆盖矩阵)

//给定一个由字符组成的矩阵,求出它的面积最小的覆盖矩阵 //可以求出每一行的最小覆盖子串的长度,只要对这些长度求最小公倍数,就可以获得最小覆盖矩阵的宽度. //同理,求出每一列的最小覆盖子串的长度,再求最小公倍数,就可以获得最小覆盖矩阵的高度了. # include <stdio.h> # include <string.h> # include <algorithm> using namespace std; char a[10010][100]; int next

POJ 2455 Secret Milking Machine(搜索-二分,网络流-最大流)

Secret Milking Machine Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9658   Accepted: 2859 Description Farmer John is constructing a new milking machine and wishes to keep it secret as long as possible. He has hidden in it deep within

POJ 2455Secret Milking Machine(二分+网络流之最大流)

题目地址:POJ2455 手残真浪费时间啊..又拖到了今天才找出了错误..每晚两道题不知不觉又变回了每晚一道题...sad.. 第一次在isap中忘记调用bfs,第二次则是遍历的时候居然是从1开始遍历的...sad... 这题思路倒是很简单,就是有一个比较坑的地方,就是这里的重边要当两条边来用,以前受最短路什么的影响,直接把慢的删了,很明显不对...这里的两条重边都是可以走的. 建图思路是,将1当作源点,将n当作汇点.右边的地方就连边,注意是无向边.最后判断最大流是否等于道路条数.二分找最小值.