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

Sample Input

12 4 2
1 2 8
10 12 19
3 6 24
7 10 31

Sample Output

43
/*
题意:奶牛在0~n的区间内产奶,农场主有m个时间段可以挤奶并且给出第i个时间段的挤奶产量,农场主每次挤完奶之后必须休息时间r之后
才能工作,问农场主最多可以挤多少奶 初步思路:贪心 #错误:贪心解决不了问题还是得动态规划,dp[i]表示第i个时间段能获得的最大奶量,dp[i]=max(dp[i],dp[j]+fr[i].val);
注意这个dp[j]的结束时间不能和dp[i]的开始时间冲突
*/
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
struct node{
int l,r,val;
bool operator < (const node & other) const{
if(l==other.l) return r<other.r;
return l<other.l;
}
}fr[];
int dp[];
int m,n,r;
int maxn;
void init(){
memset(dp,,sizeof dp);
maxn=-;
}
int main(){
// freopen("in.txt","r",stdin);
while(scanf("%d%d%d",&n,&m,&r)!=EOF){
init();
for(int i=;i<=m;i++){
scanf("%d%d%d",&fr[i].l,&fr[i].r,&fr[i].val);
fr[i].r+=r;
}
sort(fr+,fr+m+);
for(int i=;i<=m;i++){
dp[i]=fr[i].val;
for(int j=;j<i;j++){
if(fr[j].r<=fr[i].l){
dp[i]=max(dp[i],dp[j]+fr[i].val);
}
}
maxn=max(dp[i],maxn);
}
printf("%d\n",maxn);
}
return ;
}

Milking Time的更多相关文章

  1. POJ2455Secret Milking Machine[最大流 无向图 二分答案]

    Secret Milking Machine Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11865   Accepted ...

  2. Milking Cows

    Milking Cows Three farmers rise at 5 am each morning and head for the barn to milk three cows. The f ...

  3. POJ 2185 Milking Grid KMP(矩阵循环节)

                                                            Milking Grid Time Limit: 3000MS   Memory Lim ...

  4. Optimal Milking 分类: 图论 POJ 最短路 查找 2015-08-10 10:38 3人阅读 评论(0) 收藏

    Optimal Milking Time Limit: 2000MS Memory Limit: 30000K Total Submissions: 13968 Accepted: 5044 Case ...

  5. POJ2112 Optimal Milking (网络流)(Dinic)

                                             Optimal Milking Time Limit: 2000MS   Memory Limit: 30000K T ...

  6. 洛谷P1204 [USACO1.2]挤牛奶Milking Cows

    P1204 [USACO1.2]挤牛奶Milking Cows 474通过 1.4K提交 题目提供者该用户不存在 标签USACO 难度普及- 提交  讨论  题解 最新讨论 请各位帮忙看下程序 错误 ...

  7. 【USACO】Milking Cows

    Three farmers rise at 5 am each morning and head for the barn to milk three cows. The first farmer b ...

  8. POJ 2185 Milking Grid(KMP)

    Milking Grid Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 4738   Accepted: 1978 Desc ...

  9. poj 3616 Milking Time

                                                                                                 Milking ...

  10. codeforce ---A. Milking cows

    A. Milking cows time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

随机推荐

  1. WEB中的敏感文件泄漏

    文件泄露, 根据泄漏的信息敏感程度, 在WEB漏洞中可以算是中危甚至高危的漏洞, 本篇文章就来 介绍下一些常见的泄漏, 主要分为由版本管理软件导致的泄露, 文件包含导致的泄露和配置错误导致的泄露. 版 ...

  2. java ee Servlet 开发框架分享

    大家好! 这里分享一下javaEE Servlet开发框架! 1.首先是POST和GET入口以及接收处理文件 package com.sl.imps; import java.io.IOExcepti ...

  3. 【】小技巧】CSS文字两端对齐

    需求如下,红框所在的文字有四个字的.三个字的.两个字的,如果不两端对齐可以选择居中对齐,或者右对齐.但是如果要像下面这样两端对齐呢? 我相信以前很多人都这么干过:两个字中间使用 来隔开达到四个字的宽度 ...

  4. 详细解读-this-关键字在全局、函数、对象、jQuery中的基础用法!

    一.前言 1. Javascript是一门基于对象的动态语言,也就是说,所有东西都是对象,一个很典型的例子就是函数也被视为普通的对象.Javascript可以通过一定的设计模式来实现面向对象的编程,其 ...

  5. HTTP协议报文、工作原理

    一.web及网络基础       1.HTTP的历史            1.1.HTTP的概念:                 HTTP(Hyper Text Transfer Protocol ...

  6. Cookie实现登录记住密码

    Cookie实现记住登录密码,用户可以自由选择是否记住密码,或者用户之前选择记住了,但是某一次又不想记住了,需要将之前对应的Cookie删除掉 Cookie相当于map 也是键值对的形式,但是并不相同 ...

  7. 如何从两个List中筛选出相同的值

    问题 现有社保卡和身份证若干,想要匹配筛选出一一对应的社保卡和身份证. 转换为List socialList,和List idList,从二者中找出匹配的社保卡. 模型 创建社保卡类 /** * @a ...

  8. 记XDCTF的misc之旅---base64隐写

    bWFpbigpe2ludCBpLG5bXT17KCgoMSA8PDEpPDwgKDE8PDEpPDwoMTw8Cm==ICAgICAgIDEpPDwoMTw8KDE+PjEpKSkrKCgxPDwx ...

  9. 数据分析前戏:ipython使用技巧(上)

    不一定非得使用Jupyter Notebook,试试ipython命令行 安装 ipython 我只试过Windows 10环境下的. 1.安装python安装包之后,应该就有ipython了. 2. ...

  10. hdu1878判断欧拉回路

    欧拉回路 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...