Milking Time
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 7265   Accepted: 3043

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_houriN), an ending hour (starting_houri < ending_houriN), 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 ≤ RN) 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

Source

 
题意:挤奶工工作的区间是 1 - N (hour),农场主有m个时间段要挤奶工挤奶,每一个时间段都有一个 起始时间 结束时间 以及在这段时间内可以获得的利益 。而且挤奶工每工作
完一个时间段就要休息r分钟,求挤奶工在 这m个时间段中能够获得的最大利益。
 
题解:dp[i]表示在前 i 段时间挤奶工能够获得的最大收益,对前m段时间按起始时间升序排个序,起始时间相同按照结束时间升序排列。我们就可以得到状态转移方程. dp[i] = max(dp[j]+value[i],dp[i])&&mk[j].e+r<=mk[i].s (1=<j<i)
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
const int N = ;
const int M = ;
int dp[N]; ///dp[i]表示在前i组时间中能取得的最大利益
struct Milk{
int s,e,v;
}mk[M];
int cmp(Milk a,Milk b){
if(a.s!=b.s) return a.s<b.s;
return a.e<b.e;
}
int main()
{
int n,m,r;
while(scanf("%d%d%d",&n,&m,&r)!=EOF)
{
for(int i=;i<=m;i++){
scanf("%d%d%d",&mk[i].s,&mk[i].e,&mk[i].v);
}
memset(dp,,sizeof(dp));
sort(mk+,mk++m,cmp);
int mx = -;
for(int i=;i<=m;i++){
dp[i] = mk[i].v;
for(int j=;j<i;j++){
if(mk[j].e+r<=mk[i].s&&mk[i].v+dp[j]>dp[i]){
dp[i] = dp[j] +mk[i].v;
}
}
if(dp[i]>mx) mx = dp[i];
}
printf("%d\n",mx);
}
return ;
}

poj 3616(动态规划)的更多相关文章

  1. POJ - 3616 Milking Time (动态规划)

    Bessie is such a hard-working cow. In fact, she is so focused on maximizing her productivity that sh ...

  2. 动态规划:POJ 3616 Milking Time

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

  3. 【POJ - 3616】Milking Time(动态规划)

    Milking Time 直接翻译了 Descriptions 贝茜是一个勤劳的牛.事实上,她如此​​专注于最大化她的生产力,于是她决定安排下一个N(1≤N≤1,000,000)小时(方便地标记为0. ...

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

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

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

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

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

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

  7. poj 3616 Milking Time (基础dp)

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

  8. nyoj 17-单调递增最长子序列 && poj 2533(动态规划,演算法)

    17-单调递增最长子序列 内存限制:64MB 时间限制:3000ms Special Judge: No accepted:21 submit:49 题目描述: 求一个字符串的最长递增子序列的长度 如 ...

  9. poj 3034 动态规划

    思路:这是一道坑爹的动态规划,思路很容易想到,就是细节. 用dp[t][i][j],表示在第t时间,锤子停在(i,j)位置能获得的最大数量.那么只要找到一个点转移到(i,j)收益最大即可. #incl ...

随机推荐

  1. bzoj3680: 吊打XXX(模拟退火)

    题目要求 最小(dis表示绳结到点i的距离),就是个广义费马点的题,模拟退火裸题QAQ 模拟退火就是优化后的爬山算法,一开始先随机一个平均点,接下来如果随机到的点比当前点劣,温度比较高的话也有几率跳过 ...

  2. 51nod 1275 连续子段的差异(twopointer+单调队列)

    对于每一个i找到最近的j满足最大值-最小值>K,对答案的贡献为j-i,用单调队列维护最值即可 #include<iostream> #include<cstdlib> # ...

  3. Django CRM系统

    本节内容 业务痛点分析 项目需求讨论 使用场景分析 表结构设计 业务痛点分析 我2013年刚加入老男孩教育的时候,学校就一间教室,2个招生老师,招了学生后,招生老师就在自己的excel表里记录一下,每 ...

  4. xshell如何让窗口并列排序

    如图所示:

  5. mybatis逆向工程生成mapper报错

    Result Maps collection already contains value for xxxMapper.BaseResultMap错误解决办法一.问题描述今天在做项目时,遇到一个错误: ...

  6. DOM学习控件定位和案例

    Dom中有多种定位属性,下面是一个简单案例 <html><!--制作一个会跟着鼠标走的图像,还有控件定位的案例--> <head> <title>doc ...

  7. ACM1004 Let the balloons fly

    These code is for the problem "Let the balloons Fly" in ACM 1004 which need deal with stri ...

  8. unbuntu 14.04 安装搜狗输入法

    http://blog.csdn.net/leijiezhang/article/details/53707181

  9. MongoDB入门(4)- MongoDB日常操作

    MongoDB客户端 MongoDB有很多客户端 MongoVue Robomongo MongoDB命令行 启动mongo shell 在windows下,双击mongo.exe可以启动mongo ...

  10. 解决Sourcetree 每次拉取提交都需要输入密码

    问题产生背景 客户端领导决定使用http方式拉取和push代码,所以无法使用之前的ssh方式做免密处理 解决办法 方法1:在.git目录中有个config目录,在路径前配置下用户名和密码即可,如下所示 ...