Problem 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

题意:已知一时间段n,在这个时间段内有m段时间,以及工作后需休息r小时后才能再次工作,其后分别给出这m段时间内每段的开始时间、结束时间、工作量,求最大工作量。

思路:将m段时间段按照他们的结束时间升序排序,用f[i]表示取到第i段时间时的最大值,如果第i个时间段之前的一个时间段的结束时间加上r小于第i段的开始时间,更新最大值。

即:if(time[i].start>=time[j].end+r)

f[i]=max(f[i],f[j]+time[i].value);

Source Program

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<queue>
#include<vector>
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define N 100001
#define MOD 1001
#define E 1e-12
using namespace std;
int f[N];
struct Node{int start;int endd;int value;
}time[N];
bool cmp(Node a,Node b)
{return a.endd<b.endd;}
int main()
{int n,m,r;scanf("%d%d%d",&n,&m,&r);for(int i=1;i<=m;i++)scanf("%d%d%d",&time[i].start,&time[i].endd,&time[i].value);sort(time+1,time+m+1,cmp);//按结束时间升序排序int maxx=-INF;time[0].endd=-r;for(int i=1;i<=m;i++){for(int j=0;j<i;j++)if(time[i].start>=time[j].endd+r)//如果第i个时间段之前的一个时间段的结束时间加上r小于第i段的开始时间f[i]=max(f[i],f[j]+time[i].value);//更新最大值maxx=max(maxx,f[i]);}printf("%d\n",maxx);
}

Milking Time(POJ-3616)相关推荐

  1. Bailian2734 十进制到八进制【入门】(POJ NOI0113-45)

    问题链接:POJ NOI0113-45十进制到八进制 2734:十进制到八进制 总时间限制: 1000ms 内存限制: 65536kB 描述 把一个十进制正整数转化成八进制. 输入 一行,仅含一个十进 ...

  2. Bailian2676 整数的个数【入门】(POJ NOI0105-11)

    问题链接:POJ NOI0105-11 整数的个数 2676:整数的个数 总时间限制: 1000ms 内存限制: 65536kB 描述 给定k(1 < k < 100)个正整数,其中每个数 ...

  3. Bailian4029 数字反转【进制】(POJ NOI0105-29)

    问题链接:POJ NOI0105-29 数字反转 4029:数字反转 总时间限制: 1000ms 内存限制: 65535kB 描述 给定一个整数,请将该数各个位上数字反转得到一个新数.新数也应满足整数 ...

  4. Bailian2735 八进制到十进制【入门】(POJ NOI0113-46)

    问题链接:POJ NOI0113-46 八进制到十进制 2735:八进制到十进制 总时间限制: 1000ms 内存限制: 65536kB 描述 把一个八进制正整数转化成十进制. 输入 一行,仅含一个八 ...

  5. Silver Cow Party (POJ - 3268 )

    Silver Cow Party (POJ - 3268 ) 这道题是我做的最短路专题里的一道题,但我还没做这个,结果比赛就出了,真是.......... 题目: One cow from each ...

  6. 吴昊品游戏核心算法 Round 7 —— 熄灯游戏AI(有人性的Brute Force)(POJ 2811)

    暴力分为两种,一种属于毫无人性的暴力,一种属于有人性 的暴力.前面一种就不说了,对于后面一种情况,我们可以只对其中的部分问题进行枚举,而通过这些子问题而推导到整个的问题中.我称之为有人性的Brute ...

  7. 【二分】Best Cow Fences(poj 2018)

    Best Cow Fences poj 2018 题目大意: 给出一个正整数数列,要你求平均数最大,长度不小于M的字串,结果乘1000取整 输入样例 10 6 6 4 2 10 3 8 5 9 4 1 ...

  8. 昂贵的聘礼(poj 1062)

    Description 年轻的探险家来到了一个印第安部落里.在那里他和酋长的女儿相爱了,于是便向酋长去求亲.酋长要他用10000个金币作为聘礼才答应把女儿嫁给他.探险家拿不出这么多金币,便请求酋长降低 ...

  9. 主席树学习小结(POJ 2104)

    在高中的时候就听到过主席树了,感觉非常高端,在寒假的时候 winter homework中有一题是查找区间第K大的树,当时就开始百度这种网上的博客,发现主席树看不懂,因为那个root[i],还有tx[ ...

  10. A - TOYS(POJ - 2318) 计算几何的一道基础题

    Calculate the number of toys that land in each bin of a partitioned toy box. 计算每一个玩具箱里面玩具的数量 Mom and ...

最新文章

  1. python快速编程入门课后题答案-python语言程序设计基础(嵩天)第四章课后习题部分答案...
  2. Windows 10 RedStone2值得期待的五大功能猜想
  3. 迁移到其他机器_有赞大数据离线集群迁移实战
  4. jdk的Selector(3)select的过程
  5. python opencv 内存泄露_python - OpenCV Python裁剪图像 - 堆栈内存溢出
  6. mysql 行转列_详解MySQL行列转换4个实现方案及反向行转列实验测试
  7. JavaScript的类型转换(字符转数字,数字转字符)
  8. java读properties的通用类,兼容linux和windows
  9. 1048 数字加密.测试点2.5
  10. 感知机不能表示“异或”
  11. 人工智能续写贝多芬生前未完成的《第十交响曲》【智能快讯】
  12. 云计算laas、paas、saas介绍和分类
  13. 服务器vga转hdmi显示器不亮,如何排除HDMI转VGA的常见故障_排除故障的四种方法
  14. Dao层和Service层的区别
  15. 决斗吧4G LTE:联发科helio步步紧逼,高通裁员步步惊心---国际电子商情
  16. 作为一个计算机专业的学生,除了教材,这些书籍你读过多少?
  17. LeetCode 10. Regular Expression Matching / 44. Wildcard Matching
  18. Quartz配置资源介绍
  19. 深度学习中GPU的作用
  20. 城市交通的5D模式 | 不同尺度下研究的城市交通

热门文章

  1. 1947-2021 NBA总冠军次数排行榜
  2. 为什么Siri总是像个智障?智能助手背后的技术到底有多难?
  3. 新手上路必学的Python函数基础知识,全在这里了(多段代码举例)
  4. python大一基础题_python基础练习题
  5. 让你的Mac电脑高效起来,推荐几个yyds的命令行工具
  6. YGC问题排查,又让我涨姿势了!
  7. 99%的程序员都在用Lombok,原理竟然这么简单?我也手撸了一个!
  8. CentOS7安装详解
  9. redis学习及实践3---Jedis、JedisPool、Jedis分布式实例介绍
  10. 专题开发十二:JEECG微云快速开发平台-基础用户权限