Milking Time
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 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的更多相关文章
- POJ2455Secret Milking Machine[最大流 无向图 二分答案]
Secret Milking Machine Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11865 Accepted ...
- Milking Cows
Milking Cows Three farmers rise at 5 am each morning and head for the barn to milk three cows. The f ...
- POJ 2185 Milking Grid KMP(矩阵循环节)
Milking Grid Time Limit: 3000MS Memory Lim ...
- Optimal Milking 分类: 图论 POJ 最短路 查找 2015-08-10 10:38 3人阅读 评论(0) 收藏
Optimal Milking Time Limit: 2000MS Memory Limit: 30000K Total Submissions: 13968 Accepted: 5044 Case ...
- POJ2112 Optimal Milking (网络流)(Dinic)
Optimal Milking Time Limit: 2000MS Memory Limit: 30000K T ...
- 洛谷P1204 [USACO1.2]挤牛奶Milking Cows
P1204 [USACO1.2]挤牛奶Milking Cows 474通过 1.4K提交 题目提供者该用户不存在 标签USACO 难度普及- 提交 讨论 题解 最新讨论 请各位帮忙看下程序 错误 ...
- 【USACO】Milking Cows
Three farmers rise at 5 am each morning and head for the barn to milk three cows. The first farmer b ...
- POJ 2185 Milking Grid(KMP)
Milking Grid Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 4738 Accepted: 1978 Desc ...
- poj 3616 Milking Time
Milking ...
- codeforce ---A. Milking cows
A. Milking cows time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
随机推荐
- ”TCP连接“究竟是什么意思?
我们经常听到"建立TCP连接","服务器的连接数量有限"等,但仔细一想,连接究竟是个什么东西,是和电话一样两端连起一根线?似乎有点抽象不是么? 1. 久违的分组 ...
- 【】小技巧】CSS文字两端对齐
需求如下,红框所在的文字有四个字的.三个字的.两个字的,如果不两端对齐可以选择居中对齐,或者右对齐.但是如果要像下面这样两端对齐呢? 我相信以前很多人都这么干过:两个字中间使用 来隔开达到四个字的宽度 ...
- Thinkphp5.0 在自己定义一个公共方法的控制器并且继承了Controller类的时候报错
在建立网站的时候,你通常想着把一些共有的方法提取出来,放入一个控制器内,如果你是将业务逻辑写入了构造函数里面,那么就得注意了. 在thinkphp5.0当中,有一个初始化的方法,类似于构造函数,那就是 ...
- 01.python基础知识_01
一.编译型语言和解释型语言的区别是什么? 1.编译型语言将源程序全部编译成机器码,并把结果保存为二进制文件.运行时,直接使用编译好的文件即可 2.解释型语言只在执行程序时,才一条一条的解释成机器语言给 ...
- C++运算符优先级 案例1
问: ... short nReaderCount=10 ++pLock->nReaderCount==? ...++和->同为1级优先级,我想很多也有很多新手弄 ...
- python之路第五篇之模块和加密算法(进阶篇:续)
模块 Python中,如果要引用一些内置的函数,该怎么处理呢?在Python中有一个概念叫做模块(module) 简单地说,模块就是一个保存了Python代码的文件. 模块分类: 1)内置模块 2)自 ...
- python 多线程和多进程的区别 mutiprocessing theading
多线程可以共享全局变量,多进程不能.多线程中,所有子线程的进程号相同:多进程中,不同的子进程进程号不同. #!/usr/bin/python # -*- coding:utf-8 -*- import ...
- C#综合揭秘——细说多线程(二)
/* 异步写入 FileStream中包含BeginWrite.EndWrite 方法可以启动I/O线程进行异步写入. public override IAsyncResult BeginWrite ...
- EsRejectedExecutionException排错与线程池类型
1.EsRejectedExecutionException异常示例 java.util.concurrent.ExecutionException: RemoteTransportException ...
- MySQL(十五)之数据备份中mysqldump详解
前言 其实前面一篇数据备份已经是非常的详细了,这里我想单独的讲解一下mysqldump,相信很多程序员都是用过这个命令的! 一.MySQL数据库的备份与还原 1.1.MySQL数据库备份 1)语法 m ...