POJ 3616 Milking Time


Milking Time
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 3852   Accepted: 1623

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_houriN), an ending hour (starting_houri < ending_houriN), 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 ≤ RN) 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


题目大意:告诉你总时间n,m个容器,以及时间间隔 t, 接下来是m段区间以及各区间的值,问你 用这m个容器最多获得多大的值。 

解题思路,按照左端点排序,依次更新后面的点


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

const int maxn=1100;
int dp[1000010],n,m,t;

struct milk{
    int l,r,c;
    milk(int l0=0,int r0=0,int c0=0){
        l=l0;r=r0;c=c0;
    }
    friend bool operator < (milk a,milk b){
        return a.l<b.l;
    }
}p[maxn];

void initial(){
    memset(dp,0,sizeof(dp));
}

void input(){
    for(int i=0;i<m;i++){
        scanf("%d%d%d",&p[i].l,&p[i].r,&p[i].c);
    }
}

void computing(){
    sort(p,p+m);
    for(int i=0;i<m;i++){
        dp[p[i].r+t]=max(dp[p[i].r+t],p[i].c);
        for(int j=0;j<i;j++){
            if(p[j].r+t>p[i].l) continue;
            dp[p[i].r+t]=max(dp[p[i].r+t],dp[p[j].r+t]+p[i].c);
        }
    }
    int ans=0;
    for(int i=0;i<=n+t;i++){
        if(dp[i]>ans) ans=dp[i];
    }
    cout<<ans<<endl;
}

int main(){
    while(scanf("%d%d%d",&n,&m,&t)!=EOF){
        initial();
        input();
        computing();
    }
    return 0;
}


posted @ 2013-11-04 20:06  炒饭君  阅读(106)  评论(0编辑  收藏  举报