POJ 3616 Milking time (sort +DP)

Source: Internet
Author: User

Title Link: http://poj.org/problem?id=3616

Cows produce n hours (n<=1000000), but milk must be taken within m time periods, given the start and end times of each period and the quality of the milk taken.

And two times between the milk to be spaced r-1 hours, to maximize the quality of milk intake

That is, R = 2:3 to the end of the milk, at least 5 minutes to take.

In chronological order, Dp[i] represents the maximum amount of milk produced during the I period

1 //#pragma COMMENT (linker, "/stack:102400000, 102400000")2#include <algorithm>3#include <iostream>4#include <cstdlib>5#include <cstring>6#include <cstdio>7#include <vector>8#include <cmath>9#include <ctime>Ten#include <list> One#include <Set> A#include <map> - using namespacestd; -typedefLong LongLL; thetypedef pair <int,int>P; - Const intN = 1e3 +5; - structData { -     intL, R, Val; +     BOOL operator< (Constdata& CMP)Const { -         returnL <CMP.L; +     } A }a[n]; at intDp[n]; -  - intMain () - { -     intN, M, R; -      while(~SCANF (" %d%d%d", &n, &m, &r)) { inMemset (DP,0,sizeof(DP)); -          for(inti =1; I <= m; ++i) { toscanf" %d%d%d", &AMP;A[I].L, &AMP;A[I].R, &a[i].val); +         } -Sort (A +1, A + M +1); the         intres =0; *          for(inti =1; I <= m; ++i) { $Dp[i] =A[i].val;Panax Notoginseng              for(intj =1; J < I; ++j) { -                 if(A[I].L-A[J].R >=r) { theDp[i] = max (Dp[i], dp[j] +a[i].val); +                 } A             } theres =Max (res, dp[i]); +         } -printf"%d\n", res); $     } $     return 0; -}

POJ 3616 Milking time (sort +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.