POJ 3616 milking Time (DP)

Source: Internet
Author: User

Description

Bessie isSuch a hard-working cow. In fact, she isSo focused in maximizing her productivity, she decides to schedule her next N (1≤n≤1, the, the) hours (conveniently labeled0.. N-1) so that she produces asMuch milk aspossible. Farmer John has a list of of M (1≤m≤1, the) possibly overlapping intervalsinchwhich he isAvailable forMilking. Each interval I have a starting hour (0≤starting_houri≤n), an ending hour (Starting_houri < ending_houri≤n), and a corresponding efficiency (1≤efficiencyi≤1, the, the) which indicates how many gallons of milk that he canGet  outof BessieinchThat interval. Farmer John starts and stops milking at the beginning of the starting hour and ending hour, respectively. When being milked, Bessie must is milked through an entire interval. Even Bessie had 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 produceinchThe N hours.

Input

1: Three space-separated integers:n, M, and R2.. m+1: Line i+1 describes FJ's ith milking interval withthree space-separated Integers:star Ting_houri, Ending_houri, and Efficiencyi

Output

1  in the N hours

Sample Input

 A 4 2 1 2 8 Ten  A  + 3 6  - 7 Ten  to

Sample Output

43

Source

Usaco November Silver DP, note initialization,

for (int i=1;i<=m;i++) {
DP[I]=COWS[I].C;
}

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <queue>5#include <stdlib.h>6 using namespacestd;7 #defineN 10000068 #defineM 10069 intN,m,r;Ten structnode{ One     ints,e; A     intC; - }cows[m]; - BOOLCMP (Node A,node b) { the     if(a.s!=B.S) -       returna.s<B.S; -      returna.e<B.E; - } + intDP[M];//Dp[i] Indicates the maximum value for the period of time taken to paragraph I - intMain () + { A      while(SCANF ("%d%d%d", &n,&m,&r) = =3){ at          for(intI=1; i<=m;i++){ -scanf"%d%d%d",&cows[i].s,&cows[i].e,&cows[i].c); -         } -Sort (cows+1, cows+m+1, CMP); -Memset (DP,0,sizeof(DP)); -          for(intI=1; i<=m;i++){ indp[i]=cows[i].c; -         } to         //dp[1]=cows[1].c; +         intans=0; -          for(intI=1; i<=m;i++){ the              for(intj=1; j<i;j++){ *                 if(cows[i].s>=cows[j].e+R) { $Dp[i]=max (dp[i],dp[j]+cows[i].c);Panax Notoginseng                 } -             } theans=Max (Dp[i],ans); +         //printf ("---%d\n", ans); A         } theprintf"%d\n", ans); +     } -     return 0; $}
View Code

POJ 3616 milking Time (DP)

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.