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 Nhours

Sample Input

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

Sample Output

43

题意:
给出m个取奶时间段和该时间段内的取奶量,每次取奶之后需要休息r个时间段,问最大取奶量
思路:
按时间段右端点排序。
dp[i]表示第i个时间段取奶之后的最大取奶量。
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#define fuck(x) cout<<#x<<" = "<<x<<endl;
#define ls (t<<1)
#define rs ((t<<1)+1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const int inf = 2.1e9;
const ll Inf = ;
const int mod = ;
const double eps = 1e-;
const double pi = acos(-);
int n,m,r;
struct node{
int l,r,v;
}a[];
int dp[maxn];
bool cmp(node a,node b){
return a.r<b.r;
} int main()
{
// ios::sync_with_stdio(false);
// freopen("in.txt","r",stdin); scanf("%d%d%d",&n,&m,&r);
for(int i=;i<=m;i++){
scanf("%d%d%d",&a[i].l,&a[i].r,&a[i].v);
}
sort(a+,a++m,cmp);
int ans=;
for(int i=;i<=m;i++){
dp[i]=a[i].v;
for(int j=;j<i;j++){
if(a[j].r+r<=a[i].l){dp[i]=max(dp[i],dp[j]+a[i].v);}
}
ans=max(ans,dp[i]);
}
printf("%d\n",ans);
return ;
}

POJ - 3616 Milking Time (动态规划)的更多相关文章

  1. POJ 3616 Milking Time(加掩饰的LIS)

    传送门: http://poj.org/problem?id=3616 Milking Time Time Limit: 1000MS   Memory Limit: 65536K Total Sub ...

  2. 动态规划:POJ 3616 Milking Time

    #include <iostream> #include <algorithm> #include <cstring> #include <cstdio> ...

  3. POJ 3616 Milking Time (排序+dp)

    题目链接:http://poj.org/problem?id=3616 有头牛产奶n小时(n<=1000000),但必须在m个时间段内取奶,给定每个时间段的起始时间和结束时间以及取奶质量 且两次 ...

  4. poj 3616 Milking Time

                                                                                                 Milking ...

  5. POJ 3616 Milking Time(最大递增子序列变形)

    题目链接:http://poj.org/problem?id=3616 题目大意:给你时间N,还有M个区间每个区间a[i]都有开始时间.结束时间.生产效率(时间都不超过N),只能在给出的时间段内生产, ...

  6. poj 3616 Milking Time (基础dp)

    题目链接 http://poj.org/problem?id=3616 题意:在一个农场里,在长度为N个时间可以挤奶,但只能挤M次,且每挤一次就要休息t分钟: 接下来给m组数据表示挤奶的时间与奶量求最 ...

  7. poj 3616 Milking Time(dp)

    Description Bessie ≤ N ≤ ,,) hours (conveniently labeled ..N-) so that she produces as much milk as ...

  8. POJ 3616 Milking Time 简单DP

    题意:奶牛Bessie在0~N时间段产奶.农夫约翰有M个时间段可以挤奶,时间段f,t内Bessie能挤到的牛奶量e.奶牛产奶后需要休息R小时才能继续下一次产奶,求Bessie最大的挤奶量. 详见代码 ...

  9. POJ 3616 Milking Time (字符串DP)

    题意:找元素关于对角线左或右对称的最大矩阵 思路:左右对角线只需要遍历一条就可以了.只要当前点往上遍历和往后遍历一样就可以. #include<iostream> #include< ...

随机推荐

  1. linux中Samba服务器的配置

    Samba简介 Samba是在Linux和UNIX系统上实现SMB协议的一个免费软件,由服务器及客户端程序构成.SMB(Server Messages Block,信息服务块)是一种在局域网上共享文件 ...

  2. Kafka 安装配置 windows 下

    Kafka 安装配置 windows 下 标签(空格分隔): Kafka Kafka 内核部分需要安装jdk, zookeeper. 安装JDK 安装JDK就不需要讲解了,安装完配置下JAVA_HOM ...

  3. Jenkins+VS项目持续集成

    软件安装 安装包下载连接:https://jenkins.io/download/ 安装步奏:略 账户名:admin 密码:C:\Program Files (x86)\Jenkins\secrets ...

  4. JavaScript Uncaught TypeError: Cannot read property 'value' of null

    用 JavaScript 操作 DOM 时出现如下错误: Uncaught TypeError: Cannot set property 'value' of null Uncaught TypeEr ...

  5. JS第二部分--DOM文档对象模型

    一.DOM的概念 二.DOM可以做什么 三.DOM对象的获取 四.事件的介绍 五.DOM节点标签样式属性的操作 六.DOM节点对象对值的操作 七.DOM节点-标签属性的操作(例如id class sr ...

  6. Cookie 版购物车

    写一个JS文件  把相应的方法写在JS文件内 为了方便以后的调用 具体代码为 var Cart = function () { this.Count = 0; this.Total = 0; this ...

  7. Generative Adversarial Nets[BEGAN]

    本文来自<BEGAN: Boundary Equilibrium Generative Adversarial Networks>,时间线为2017年3月.是google的工作. 作者提出 ...

  8. PyInstaller安装使用方法

    PyInstaller可以把Python应用程序及其所有依赖项捆绑到一个包中.用户可以在不安装Python解释器或任何模块的情况下运行打包的应用程序.PyInstaller支持Python 2.7和P ...

  9. HTML5新增特性

    1. 语义化标签 2. 增强型表单 (1)新的表单输入类型 (2)新表单元素 (3)新表单属性 3. 视频和音频 4. Canvas绘图(图形.路径.文本.渐变.图像) 5. SVG绘图 (与Canv ...

  10. MySQL 字符串 分割 多列

    mysql如何进行以,分割的字符串的拆分 - 我有一个梦想 - CSDN博客https://blog.csdn.net/u012009613/article/details/52770567 mysq ...