Water DP
First sort by start time, then DP.
DP (i) represents the optimal answer for the first I time period, then DP (i) = Max (DP (j)) + w_i (0 < J < i), answer = MAX (DP (i)) (1 < = i <= m)
-------------------------------------------------------------------------------------------
#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>#define REP (i, n) for (int i = 0; i < n; ++i)#define CLR (x, C) memset (x, C, sizeof (x))using namespace std;const INT MAXN = + 5;int R;struct Data {int L, R, W;void Read () {scanf ("%d%d%d", &l, &r, &w);R + = r;}BOOL Operator < (const data &RHS) Const {return L < RHS.L;}};data a[MAXN];int d[MAXN];int main () {freopen ("test.in", "R", stdin);int n, m;cin >> n >> m >> R;Rep (i, M)a[i]. Read ();sort (A, A + m);Rep (i, m) {d[I] = 0;data* o = &a[i];Rep (J, i) {Data &x = * (A + j);if (X.R <= o-L)d[i] = max (d[i], d[j]);}d[i] + = O W;}cout << *max_element (d, D + m) << "\ n";return 0;}
-------------------------------------------------------------------------------------------
1642: [Usaco2007 nov]milking time Milking Hour: 5 Sec Memory Limit:
Submit: 609 Solved: 349
[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
Source
Bzoj 1642: [Usaco2007 nov]milking time Milking times (DP)