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", &A[I].L, &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)