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. 探索Java NIO

    什么是NIO? java.nio全称java non-blocking IO,是指jdk1.4 及以上版本里提供的新api(New IO),NIO提供了与标准IO不同的IO工作方式. 核心部分: Ch ...

  2. Clojure——学习迷宫生成

    背景 初学clojure,想着看一些算法来熟悉clojure语法及相关算法实现. 找到一个各种语言生成迷宫的网站:http://rosettacode.org/wiki/Maze_generation ...

  3. Ubuntu中MongoDB安装

    在Ubuntu中MongoDB有时候启动不起来,可以参考以下方法从新安装: 1.导入包管理系统使用的公钥 Ubuntu 的软件包管理工具(即dpkg和APT)要求软件包的发布者通过GPG密钥签名来确保 ...

  4. Jmeter脚本调试——关联(正则表达式)

    关联,在脚本中,是必应用到的一个设置方法,将脚本中,每次都会动态变化的特殊值进行关联.一个能正确执行的脚本,都需要进行关联(LR.jmeter). Jmeter关联: 在脚本回放过程中,客户端发出请求 ...

  5. 802.1Q VLAN技术原理

    文章出处:http://hi.baidu.com/x278384/item/d56b0edfd4f56a4eddf9be79 在数据通信和宽带接入设备里,只要涉及到二层技术的,就会遇到VLAN.而且, ...

  6. 将 Intent 序列化,像 Uri 一样传递 Intent!!!

    一.真的需要new一个Intent吗? 在 Android 中,打开一个 Activity ,有多少种方式?不过不管是使用什么方式,最终都没办法逃避创建一个 Intent ,然后startActivi ...

  7. Another app is currently holding the yum lock; waiting for it to exit 解决方法

    Another app is currently holding the yum lock; waiting for it to exit... The other application is: P ...

  8. The Twelve-Factor App 实践

    The Twelve-Factor App <The Twelve-Factor App>定义了一个优雅的互联网应用在设计过程中,尤其是在设计SAAS服务时,需要遵循的一些基本原则.本文为 ...

  9. 创建mongodb副本集操作实例

    一:概念 相关概念及图片引用自这里 mongodb副本集: 副本集是一组服务器,其中一个是主服务器,用于处理客户请求:还有多个备份服务器,用于保存主服务器的数据副本.如果主服务器崩溃了,备份服务器自动 ...

  10. win10 UWP button

    button有很多和wpf一样,可以看<深入浅出WPF> 我们可以在button的click写上 <Button Content="确定" Click=" ...