Bzoj 1642: [usaco2007 Nov] milking time

Source: Internet
Author: User
Description

Bessie is a very hard-working cow who is always focused on improving her production. To produce more milk, she expected the next N (1 ≤ n ≤ 1,000,000) hours, marked as 0 .. N-1. Farmer John planned M (1 ≤ m ≤ 1,000) milking time periods. Each time period has a start time (0 ≤ start time ≤ n), an end time (start time <End time ≤ n), and a yield (1 ≤ output ≤ 1,000,000) indicates the amount of milk that can be milked from Bessie. Farmer John milking from the start time to the end time respectively. The entire time period must be used for each milking. But even Bessie has her production limit. After each milking, she had to rest r (1 ≤ r ≤ n) hours before the next milking. Given the time range planned by farmer John, calculate the maximum amount of milking in N hours. Input

Three integers n, m, R. Next m in row 1st, three integers Si, EI, Pi. Output in each row

Maximum milk yield.

Question:

First, sort the time period by the end time, and define f [I] as the maximum benefit from the start time to the period I.

F [I] = max {f [J]} + W [I]

J <I and the end time of J + R is before the start time of I.

Ans = max {f [I]}

Code:

#include<cstdio>#include<cstring>#include<algorithm>//by zrt//problem:using namespace std;int n,m,r;int f[1005];struct N{    int s,e,p;    friend bool operator < (N a,N b){        return a.e<b.e;    }}a[1005];int inf=1<<30;int main(){    #ifdef LOCAL    freopen("in.txt","r",stdin);    freopen("out.txt","w",stdout);    #endif    scanf("%d%d%d",&n,&m,&r);    for(int i=1;i<=m;i++){        scanf("%d%d%d",&a[i].s,&a[i].e,&a[i].p);    }    a[0].e=-inf;    sort(a,a+1+m);    int ans=0;    for(int i=1;i<=m;i++){        for(int j=0;j<i;j++){            if(a[j].e+r<=a[i].s){                f[i]=max(f[i],f[j]+a[i].p);            }        }        ans=max(ans,f[i]);    }         printf("%d\n",ans);    return 0;}

Bzoj 1642: [usaco2007 Nov] milking time

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.