"Bzoj 1642" [Usaco2007 nov]milking time Milking times

Source: Internet
Author: User

1642: [Usaco2007 nov]milking time Milking Hour: 5 Sec Memory Limit:
Submit: 590 Solved: 337
[Submit] [Status] [Discuss] Description

Bessie was a very hard-working cow, and she always focused on improving her own production. In order to produce more milk, she expected the next N (1≤n≤1,000,000) hours, labeled 0. N-1. Farmer John planned to 1≤m≤1,000 a time period for milking. Each time period has a start time (0≤ start time ≤n), and an end time (start time < end time ≤n), and a yield (1≤ yield ≤1,000,000) represents the amount of milk that can be milked from Bessie. Farmer John is milking from the start time to the end time respectively. Each milking must use the entire time period. But even Bessie had her production limits. After each milking, she must rest R (1≤r≤n) hours before milking next time. Given the time period of the farmer John Program, please calculate the maximum amount of milking in N hours.

Input

Section1row of three integersN,M,R.NextMrows, three integers per lineSi,Ei,Pi.

Output

the maximum amount of milk produced.

Sample Input12 4 2
1 2 8
10 12 19
3 6 24
7 10 31
Sample Output +HINT

Note: End time not milking


Dp.


Sort by start and end time, then DP:

F[i] Indicates the maximum amount of milk to be extruded using the first I milking time.


F[i]=max (F[k]+w[i]) (A[K].E+R<=A[I].S)


Notice the end time not milking!! means this is <=.

#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include < Cstdio>using namespace Std;int n,m,r;struct data{int s,e,v;} A[1005];int f[1005];bool cmp (data a,data b) {if (A.S==B.S) return A.e<b.e;return A.S<B.S;} int main () {    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].V); sort (a+1,a+1+m,cmp); f[1]=a[1].v;int ans=f[1];for (int i=2;i<=m;i++) {f[i]=a[i].v;for (int j=1;j <i;j++) if (A[J].E+R<=A[I].S) F[i]=max (F[I],F[J]+A[I].V); Ans=max (F[i],ans);} Cout<<ans<<endl;return 0;}


"Bzoj 1642" [Usaco2007 nov]milking time Milking times

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.