poj 3616 Milking Time dp
Posted xjhz
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了poj 3616 Milking Time dp相关的知识,希望对你有一定的参考价值。
Description
Bessie is such a hard-working cow. In fact, she is so focused on maximizing her productivity that she decides to schedule her next N (1 ≤ N ≤ 1,000,000) hours (conveniently labeled 0..N-1) so that she produces as much milk as possible.
Farmer John has a list of M (1 ≤ M ≤ 1,000) possibly overlapping intervals in which he is available for milking. Each interval i has a starting hour (0 ≤ starting_houri ≤ N), an ending hour (starting_houri <ending_houri ≤ N), and a corresponding efficiency (1 ≤ efficiencyi ≤ 1,000,000) which indicates how many gallons of milk that he can get out of Bessie in that interval. Farmer John starts and stops milking at the beginning of the starting hour and ending hour, respectively. When being milked, Bessie must be milked through an entire interval.
Even Bessie has 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 produce in the N hours.
Input
* Line 1: Three space-separated integers: N, M, and R
* Lines 2..M+1: Line i+1 describes FJ‘s ith milking interval withthree space-separated integers: starting_houri , ending_houri , and efficiencyi
Output
* Line 1: The maximum number of gallons of milk that Bessie can product in the N hours
Sample Input
12 4 2 1 2 8 10 12 19 3 6 24 7 10 31
Sample Output
43
Source
#include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> using namespace std; #define ll long long #define mod 1000000007 #define esp 0.00000000001 const int N=1e5+10,M=1e6+10,inf=1e9; struct is { int l,r,p; }a[N]; int cmp(is x,is y) { if(x.r!=y.r) return x.r<y.r; return x.l<y.l; } int dp[M]; int main() { int x,y,z,i,t; while(~scanf("%d%d%d",&x,&y,&z)) { memset(dp,0,sizeof(dp)); for(i=0;i<y;i++) scanf("%d%d%d",&a[i].l,&a[i].r,&a[i].p); sort(a,a+y,cmp); for(i=0;i<y;i++) { dp[a[i].r]=max(dp[max(0,a[i].l-z)]+a[i].p,max(dp[a[i].r],dp[a[i].r-1])); if(i!=y-1) { int num=a[i].r+1; while(num<a[i+1].r) dp[num]=dp[num-1],num++; } } printf("%d\n",dp[a[y-1].r]); } return 0; }
以上是关于poj 3616 Milking Time dp的主要内容,如果未能解决你的问题,请参考以下文章