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. 推荐一款JQuery星形评级插件

    jRating 是一个非常灵活的jQuery插件用于快速创建一个Ajax星型投票系统.可以设置星型数量和小数支持.功能很强大,具体大家可以看一下这个插件的js代码就知道了,下面这里演示一下这个插件有哪 ...

  2. UIColor延伸:判断两个颜色是否相等

    不管UIColor使用CIColor,CGColor还是其他方式初始化的,其CGColor属性都是可用的.CoreGraphics中提供一个函数,用于判断两个CGColor是否相等,因此我们可以通过这 ...

  3. [codeforces/edu3]总结

    链接:http://codeforces.com/contest/609 A题: 贪心,从大到小选. B题: 考虑对立面.$C_{sum}^2-\sum{C_{a_i}^2}$ C题: 最终状态是确定 ...

  4. 搭建JavaWeb应用开发环境

    下载和安装Tomcat服务器 下载Tomcat安装程序包:http://tomcat.apache.org/,下载一个zip版本,解压到本地即完成了Tomcat的安装. 测试是否安装成功:进入Tomc ...

  5. DFS搜索题素数环

    素数环: 输入整数1,2,3,4,5,···,n组成一个环,使得相邻两个整数之和均为素数. 输出时从整数1开始逆时针排列.同一个环应恰好输出一次.n<=16. Sample: input: 6 ...

  6. 美国选举问题/完全背包/Knapsack

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Knap ...

  7. DIV CSS display(block,inline,none)的属性教程

    display:inline.block.inline-block的区别 display:block就是将元素显示为块级元素. block元素的特点是: 总是在新行上开始: 高度,行高以及顶和底边距都 ...

  8. Matlab 工具箱介绍

    Toolbox工具箱 序号 工具箱 备注 数学.统计与优化 1 Symbolic Math Toolbox 符号数学工具箱 2 Partial Differential Euqation Toolbo ...

  9. 图论:最短路-Dijkstra

    Dijkstra+堆优化具有稳定的时间复杂度,在一些数据范围要求比较严格(准确来说是图比较苛刻)的时候能够保证稳定的时间复杂度 但是Dijkstra不能够解决负边权的问题,所以在使用的时候一定要仔细读 ...

  10. 【C++对象模型】第一章 关于对象

    1.C/C++区别 C++较之C的最大区别,无疑在于面向对象,C程序中程序性地使用全局数据.而C++采用ADT(abstract data tpye)或class hierarchy的数据封装.类相较 ...