poj 3616 Milking Time
来源:互联网 发布:软件项目总结ppt 编辑:程序博客网 时间:2024/06/16 12:15
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
题意:
给出n,m,r;
有只牛想要在n小时内尽可能多的产奶
每个时间段 的效率不同
m个时间段
每次产奶必须完成哪个时间段
产奶的过程中两个时间段的时间差不能少于R
给出m个区间 每行三个数 l,r,efficient
区间可能出现重叠
对区间进行排序。
然后开始dp
时间复杂度 O(m*m)
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;struct data{ int x,y,r; bool operator < (const data &a)const { return x < a.x; }}a[1000003];int dp[1000003];int main(){ int n,m,r; while(scanf("%d%d%d",&n,&m,&r)!=-1) { memset(dp,0,sizeof(dp)); for(int i=1;i<=m;i++) { scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].r); } sort(a+1,a+m+1); int res=0; for(int i=1;i<=m;i++) { for(int j=1;j<i;j++) { if(a[j].y+r<=a[i].x&&dp[j]>dp[i]) dp[i]=dp[j]; } dp[i]+=a[i].r; res=max(res,dp[i]); } printf("%d\n",res); }}
- poj 3616 Milking Time
- POJ 3616 Milking Time
- POJ-3616-Milking Time
- poj 3616 Milking Time
- POJ 3616 Milking Time
- poj 3616 Milking Time
- Milking Time.(POJ-3616)
- POJ 3616 Milking Time
- POJ 3616 Milking Time
- POJ 3616 Milking Time
- POJ 3616 (milking time)
- POJ 3616 Milking Time
- POJ 3616 Milking Time
- poj 3616 Milking Time
- POJ 3616 Milking Time
- POJ 3616 Milking Time
- poj 3616 Milking Time
- POJ 3616 Milking Time
- 关于Edittext首位为0多种情况考虑
- WEB 输入校验正则表达式
- requests库入门-11-自定义请求
- 判断字符数组中是否所有的字符只出现了一次(左程云)非递归堆排序实现
- UGUI 学习笔记 2 静态字体
- poj 3616 Milking Time
- 软件测试——测试流程重要性
- LeetCode(38)--Count and Say
- hibernate_事务处理、session管理
- C# 后台分页
- 两分钟理解Android中PX、DP、SP的区别
- class类命名
- (1)自动化selenium准备与元素定位代码
- 2512: 小明的惩罚