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. bzoj 1111 [POI2007]四进制的天平Wag 数位Dp

    1111: [POI2007]四进制的天平Wag Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 302  Solved: 201[Submit][St ...

  2. HDU1540 区间合并

    Tunnel Warfare Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  3. hbase监控简单实用脚本

    我们以前使用过的对hbase和hdfs进行健康检查,及剩余hdfs容量告警,简单易用 1.针对hadoop2的脚本: #/bin/bashbin=`dirname $0`bin=`cd $bin;pw ...

  4. 【java】AES加密解密|及Base64的使用

    转载自:http://www.cnblogs.com/arix04/archive/2009/10/15/1511839.html AES加解密算法,使用Base64做转码以及辅助加密: packag ...

  5. jQuery中 $.extend 和 $.fn.extend 作用及区别

    jQuery为开发插件提拱了两个方法,分别是: 1. jQuery.fn.extend(); 2. jQuery.extend(); 虽然 javascript没有明确的类的概念,但是可以构建类似类的 ...

  6. UVA 1635 Irrelevant Elements

    https://vjudge.net/problem/UVA-1635 题意:n个数,每相邻两个求和,最后变成1个数,问这个数除m的余数与第几个数无关 n个数使用次数分别为C(n-1,i) i∈[0, ...

  7. 图论:Floyd-多源最短路、无向图最小环

    在最短路问题中,如果我们面对的是稠密图(十分稠密的那种,比如说全连接图),计算多源最短路的时候,Floyd算法才能充分发挥它的优势,彻彻底底打败SPFA和Dijkstra 在别的最短路问题中都不推荐使 ...

  8. 【NOIP】提高组2012 vigenere密码

    [算法]模拟 #include<cstdio> #include<cstring> ; char sm[maxm],key[maxm],s[maxm]; int len,len ...

  9. 崩坏3mmd中的渲染技术研究

    http://youxiputao.com/articles/11839 主要是参考该篇文章做一个微小的复盘. 漫反射与高光 文章中的漫反射与高光并不是类似于普通的 resultCol = Diffu ...

  10. MVC4 AspNet MVC下的Ajax / 使用JQuery做相关的Ajax请求

    源码参考:链接:http://pan.baidu.com/s/1pKhHHMj  密码:mkr4 1:新建-->项目-->Web-->ASP.NET MVC 4 Web 应用程序.命 ...