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. Redux的State不应该全部放在Store里

    使用了redux管理应用的状态,应用的状态不应该全部放在Store里面. 前端状态主要有一下两种: 1. Domain data 2. UI State 1. Domain data 来自于服务端对领 ...

  2. [CodeVs1227]方格取数2(最大费用最大流)

    网络流24题的坑还没填完,真的要TJ? 题目大意:一个n*n的矩阵,每格有点权,从(1,1)出发,可以往右或者往下走,最后到达(n,n),每达到一格,把该格子的数取出来,该格子的数就变成0,这样一共走 ...

  3. 【并查集】【P1525】关押罪犯

    传送门 Description Input Output Sample Input Sample Output Hint Solution 非常显然的并查集题目,在本题中,对于每个罪犯i,维护两个信息 ...

  4. caffe数据集——LMDB

    LMDB介紹 Caffe使用LMDB來存放訓練/測試用的數據集,以及使用網絡提取出的feature(為了方便,以下還是統稱數據集).數據集的結構很簡單,就是大量的矩陣/向量數據平鋪開來.數據之間沒有什 ...

  5. mongo日常操作备忘

    修改 普通修改 插入数据: db.students.insert({ "name":"swrd", "age":32, "grad ...

  6. Base64 编解码

    Base64编码简介 Base64用来将binary的字节序列数据编码成ASCII字符序列构成的文本.其使用的字符包括大小写字母各26个,加上10个数字,和加号“+”,斜杠“/”,一共64个字符.另外 ...

  7. zigbee ------ JN5169低功耗设置

    低功耗睡眠设置Power Manager (PWRM) PWRM_vInit() 如果进入睡眠模式,设置芯片进入何种睡眠模式 PWRM_eScheduleActivity()设置进入睡眠多长时间(时钟 ...

  8. sun.security.x509.CertAndKeyGen;找不到

    导入已有项目编译时出错,报: import sun.security.x509.CertAndKeyGen;找不到 而这个包属于sun公司的jar包.不是项目本身的问题,而是开发环境的问题. 最后原因 ...

  9. 【hdu5217-括号序列】线段树

    题意:给一串括号,有2个操作,1.翻转某个括号.2.查询某段区间内化简后第k个括号是在原序列中的位置.1 ≤ N,Q ≤ 200000. 题解: 可以知道,化简后的序列一定是)))((((这种形式的. ...

  10. 【Foreign】Game [博弈论][DP]

    Game Time Limit: 20 Sec  Memory Limit: 512 MB Description 从前有个游戏.游戏分为 k 轮. 给定一个由小写英文字母组成的字符串的集合 S, 在 ...