题目链接:http://poj.org/problem?id=3616

Milking Time
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 10819   Accepted: 4556

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: NM, 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

 
 
 
题解:
经典的类LIS题型(最长上升子序列)。
类似的题:HDU1160
 
 
代码如下:
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
#define ms(a,b) memset((a),(b),sizeof((a)))
using namespace std;
typedef long long LL;
const double EPS = 1e-;
const int INF = 2e9;
const LL LNF = 2e18;
const int MAXN = 1e3+; struct node
{
int st, en, val;
bool operator<(const node &x)const{
return st<x.st;
}
}a[MAXN];
int dp[MAXN];
int N, M, R; int main()
{
while(scanf("%d%d%d", &N, &M, &R)!=EOF)
{
for(int i = ; i<=M; i++)
scanf("%d%d%d", &a[i].st, &a[i].en, &a[i].val); sort(a+, a++M);
memset(dp, , sizeof(dp));
for(int i = ; i<=M; i++)
for(int j = ; j<i; j++)
if(j== || a[i].st>=a[j].en+R )
dp[i] = max(dp[i], dp[j] + a[i].val); int ans = -INF;
for(int i = ; i<=M; i++)
ans = max(ans, dp[i]);
printf("%d\n", ans);
}
}

POJ3616 Milking Time —— DP的更多相关文章

  1. POJ3616 Milking Time【dp】

    Description Bessie is such a hard-working cow. In fact, she is so focused on maximizing her producti ...

  2. poj-3616 Milking Time (区间dp)

    http://poj.org/problem?id=3616 bessie是一头工作很努力的奶牛,她很关心自己的产奶量,所以在她安排接下来的n个小时以尽可能提高自己的产奶量. 现在有m个产奶时间,每个 ...

  3. POJ3616 Milking Time 简单DP

    注意0,1,.....,N是时间点,i~i+1是时间段 然后就是思路:dp[i]代表到时间点 i 获得的最大价值, 1:dp[i]=max(dp[i],dp[s-r]+e),表示有以s为开头,i为结尾 ...

  4. 动态规划 POJ3616 Milking Time

    #include <iostream> #include <cstdio> #include <algorithm> using namespace std; st ...

  5. poj3616 Milking Time(状态转移方程,类似LIS)

    https://vjudge.net/problem/POJ-3616 猛刷简单dp的第一天第二题. 这道题乍一看跟背包很像,不同的在于它是一个区间,背包是定点,试了很久想往背包上套,都没成功. 这题 ...

  6. POJ 3616 Milking Time DP题解

    典型的给出区间任务和效益值,然后求最大效益值的任务取法. 属于一维DP了. 一维table记录的数据含义:到当前任务的截止时间前的最大效益值是多少. 注意. 这表示当前任务一定要选择,可是终于结果是不 ...

  7. POJ3616【基础DP】

    //因为同一点结束的时间段会有多个,这里没考虑: //无限wa: const int N=1e6+7; int b[N]; LL a[N]; LL dp[N]; struct asd{ int s; ...

  8. poj3616 Milking Time

    思路: dp. 实现: #include <iostream> #include <cstdio> #include <algorithm> using names ...

  9. R - Milking Time DP

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

随机推荐

  1. CentOS 7中设置PHP7的Log文件日志

    对于服务器上面运行的php代码, 想要去查看对应的log,找到代码无法运行的原因 1.通过:phpinfo()去找 error_log 结果得到: 2.然后去编辑php.ini,修改三处地方 vi / ...

  2. spring用到的设计模式

    https://www.cnblogs.com/yuefan/p/3763898.html https://www.cnblogs.com/hwaggLee/p/4510687.html https: ...

  3. SQL ROW_NUMBER() 通用分页存储过程

    --提取分页数据,返回总记录数 Create procedure [dbo].[sp_Common_GetDataPaging_ReturnDataCount] ( @SqlString varcha ...

  4. idea与eclipse项目相互导入的过程

    idea项目导出到桌面 很简单,直接去项目所在目录考出即可,但是考出的项目往往都特别大,这是因为考出之前  我们不要忘记把idea的输出目录删除 每次启动服务器运行idea项目的时候  都会有一个输出 ...

  5. 最长回文(hdu 3068)

    Problem Description 给出一个只由小写英文字符a,b,c...y,z组成的字符串S,求S中最长回文串的长度.回文就是正反读都是一样的字符串,如aba, abba等 Input 输入有 ...

  6. 【Tomcat】如何优化tomcat配置(从内存、并发、缓存4个方面)优化

    一.Tomcat内存优化 ** Tomcat内存优化主要是对 tomcat 启动参数优化,我们可以在 tomcat 的启动脚本 catalina.sh 中设置 java_OPTS 参数. JAVA_O ...

  7. Java实现简单的图片浏览器

    第一次写博客,不喜勿喷. 最近一个小师弟问我怎么用Java做图片浏览器,感觉好久没玩Java了,就自己动手做了一下. 学校的教程是用Swing来做界面的,所以这里也用这个来讲. 首先要做个大概的界面出 ...

  8. Simics 破解 转

    http://www.eetop.cn/blog/html/28/1066428-type-bbs-view-myfav.html http://blog.sina.com.cn/s/blog_538 ...

  9. oracle 用户账户被锁处理

    一.以管理员身份登录 SQL> conn sys/sys as sysdba; (分号是必须的但是我是以system登录的所在这不应该写conn sys/sys as sysdba应该写conn ...

  10. tomcat配置访问项目时不需要加项目名称

    原文:http://blog.csdn.net/coolcoffee168/article/details/52582770 java web部署后,访问项目的时候,需要在地址中添加项目名称,那么如何 ...