POJ

来源:互联网 发布:os x 怎么恢复mac系统 编辑:程序博客网 时间:2024/05/17 05:09

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 21 2 810 12 193 6 247 10 31

Sample Output

43

分析:

代码如下:

#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int maxn = 1000;struct Cost{    int start, end, eff;}cost[maxn];int dp[maxn];//dp[i]为从i开始到N结束产奶最多数 int N,M,R;int cmp(const Cost &a, const Cost &b){    if(a.start<b.start) return 1;    else if(a.start == b.start && a.end < b.end) return 1;    else return 0;}int main(){    memset(cost, 0, sizeof(cost));    scanf("%d%d%d",&N,&M,&R);    for(int i=0; i<M; i++)    {        scanf("%d%d%d",&cost[i].start, &cost[i].end, &cost[i].eff);        cost[i].end += R;    }               sort(cost, cost+M, cmp);    for(int i=M-1; i>=0; i--)    {        dp[i] = cost[i].eff;        for(int j=i+1; j<M; j++)        {            if(cost[j].start >= cost[i].end)            {                dp[i] = max(dp[i], dp[j]+cost[i].eff);            }        }    }    int maxx=0;    for(int i=0; i<M; i++)    {        maxx = max(maxx, dp[i]);    }    printf("%d\n",maxx);    return 0;}
0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 劳保鞋鞋底太硬怎么办 在学校校服丢了怎么办 高中没进重点班怎么办 孩子不懂学不想学怎么办 孩子小学数学学不懂怎么办 入学籍系统提交了没分班怎么办 被监考老师抓了作弊怎么办 作弊被老师抓到了怎么办? 中考作弊给抓到怎么办 考试作弊证据没得监控怎么办 考试作弊被领导发现了怎么办 黄冈讲课视频看不了怎么办 高中学校不给转学籍怎么办 兴山香溪大酒店欠钱不还怎么办 黑坑青鱼滑口怎么办 不交物业费物业怎么办 车牌刮了一点漆怎么办 电脑光驱线坏了怎么办 做系统不读光驱怎么办 光盘放进电脑没反应怎么办 不服省高院裁定维持原判怎么办 咖啡和酒一起喝怎么办 跟法官联系不上怎么办 四维没有预约到怎么办 钥匙锁在车里怎么办 如果孩子很叛逆骂人打人怎么办 错过了今年规培怎么办 枣木怎么办才能搞直了 高中生和家里闹意见离家出走怎么办 校长信箱实名举报了怎么办 枣子吃多了胀气怎么办 红枣吃多了会怎么办 宁波南苑e家会员卡怎么办 宁波社保卡丢了怎么办 奶茶汉堡店经营不好改怎么办 军人保障卡丢了怎么办 军人保障卡丢失了怎么办 军人保障卡掉了怎么办 椎基底动脉供血不足怎么办 颈椎压迫神经脑供血不足怎么办 脑部基底动脉轻度狭窄怎么办