Milking Time

Time Limit: 1000MS Memory Limit: 65536K

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: 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

题意:给予M时间区间且每个区间可以挤多少牛奶,每工作一个时间段需要休息R个小时,问在N个小时最多可以得到多少牛奶。

题解:一个上升序列问题的变形。

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <cstdlib>
#include <cstring>
#include <cmath> using namespace std; const int maxn = 1050; struct node
{
int be,en,w;
}s[maxn];
int dp[maxn]; bool cmp(node a,node b)
{
if(a.be==b.be)
return a.en<b.en;
return a.be < b.be;
} int main()
{
int n,m,i,j,r,Max,mmax;
scanf("%d%d%d",&r,&m,&n);
for(i=0;i<m;i++)
scanf("%d%d%d",&s[i].be,&s[i].en,&s[i].w);
sort(s,s+m,cmp);
Max = 0;
for(i=0;i<m;i++)
{
mmax = 0;
for(j=0;j<i;j++)
{
if(s[j].en+n<=s[i].be&&mmax<dp[j])
mmax = dp[j];
};
dp[i] = mmax + s[i].w;
Max = max(Max,dp[i]);
}
printf("%d\n",Max);
return 0;
}

POJ-3616_Milking Time的更多相关文章

  1. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  2. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  3. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  4. POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Descr ...

  5. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

  6. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  7. POJ 2255. Tree Recovery

    Tree Recovery Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11939   Accepted: 7493 De ...

  8. POJ 2752 Seek the Name, Seek the Fame [kmp]

    Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17898   Ac ...

  9. poj 2352 Stars 数星星 详解

    题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...

  10. poj 1251 Jungle Roads (最小生成树)

    poj   1251  Jungle Roads  (最小生成树) Link: http://poj.org/problem?id=1251 Jungle Roads Time Limit: 1000 ...

随机推荐

  1. [转]js的键盘事件

    类型 键盘事件用来描述键盘行为,主要有keydown.keypress.keyup三个事件 keydown 当用户按下键盘上的任意键时触发,如果按住不放的话,会重复触发该事件 <div id=& ...

  2. 标记扩展和 WPF XAML

      本主题介绍 XAML 的标记扩展概念,包括其语法规则.用途以及底层的类对象模型. 标记扩展是 XAML 语言以及 XAML 服务的 .NET 实现的常规功能. 本主题专门详细论述了用于 WPF X ...

  3. CentOS7 下的 firewall 用法

    1.firewalld的基本使用 启动: systemctl start firewalld 查看状态: systemctl status firewalld  停止: systemctl disab ...

  4. 【solr】schemaFactory配置相关schema.xml

    schemaFactory配置相关schema.xml  关于schemaFactory的配置困扰我半天啦,下面来总结一下. 话说,好像是从5.0以后就已经没有schema.xml啦,这是由于Solr ...

  5. java实体类的属性名首字母不能大写,不然el表达式无法取值

    摘要:Java命名规范中,实体类属性名以小写字母开头,但并没有说不能以大写字母开头,然而事实告诉我,大写真不行 https://www.cnblogs.com/jnhs/p/10025757.html

  6. 压缩过的jQuery

    /*! jQuery v3.4.1 | (c) JS Foundation and other contributors | jquery.org/license */ !function(e,t){ ...

  7. 洛谷P2667 超级质数 [2017年6月计划 数论05]

    P2667 超级质数 题目背景 背景就是描述,描述就是背景...... 题目描述 一个质数如果从个位开始,依次去掉一位数字,两位数字,三位数字......直到只剩一位数字中间所有剩下的数都是质数,则称 ...

  8. 开始使用Apache弗林克和Mapr Streams

    Introduction MapR Ecosystem Package 2.0 (MEP) is coming with some new features related to MapR Strea ...

  9. ubuntu安装搜狗输入法后无法使用goland的快捷键 ctrl+alt+B

    安装了搜狗拼音后,其快捷键ctrl+alt+b会启动软键盘,造成与其他编辑器快捷键的冲突. 为了禁止使用ctrl+alt+b启动软键盘,可以: 1. 在搜狗拼音输入法选择设置 2. 高级设置 3. 高 ...

  10. chrome 浏览器 添加访问助手来访问网上应用商店

    chrome浏览器的强大之处,在于可以chrome浏览器的扩展程序来实现很多功能.然而不能下载扩展程序.可以借助chrome访问助手来实现: 下载chrome访问助手:https://pan.baid ...