poj 3616 Milking Time

来源:互联网 发布:软件项目总结ppt 编辑:程序博客网 时间:2024/06/16 12:15
Milking Time
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 10593 Accepted: 4435

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: NM, 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



题意:

给出n,m,r;

有只牛想要在n小时内尽可能多的产奶

每个时间段 的效率不同

m个时间段

每次产奶必须完成哪个时间段


产奶的过程中两个时间段的时间差不能少于R


给出m个区间 每行三个数 l,r,efficient

区间可能出现重叠

对区间进行排序。

然后开始dp

时间复杂度 O(m*m)

#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;struct data{    int x,y,r;    bool operator < (const data &a)const    {        return x < a.x;    }}a[1000003];int dp[1000003];int main(){    int n,m,r;    while(scanf("%d%d%d",&n,&m,&r)!=-1)    {        memset(dp,0,sizeof(dp));        for(int i=1;i<=m;i++)        {            scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].r);        }        sort(a+1,a+m+1);        int res=0;        for(int i=1;i<=m;i++)        {            for(int j=1;j<i;j++)            {                if(a[j].y+r<=a[i].x&&dp[j]>dp[i])                    dp[i]=dp[j];            }            dp[i]+=a[i].r;            res=max(res,dp[i]);        }        printf("%d\n",res);    }}


原创粉丝点击