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

题目大意:给你时间N,还有M个区间每个区间a[i]都有开始时间、结束时间、生产效率(时间都不超过N),只能在给出的时间段内生产,要求合理安排时间求出最大生产价值。

解题思路:把区间按开始时间排序,于是有状态转移方程:dp[i]=max(dp[i],dp[j]+a[i].val)(前提是a[j].end+r<=a[i].start,i是区间的序号,j是i前面的区间)

     相当于最大递增子序列的变形,写法差不多。

代码:

 #include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=1e3+; struct node{
int start,end,val;
}a[N]; bool cmp(node a,node b){
return a.start<b.start;
} int dp[N]; int main(){
int n,m,r;
while(~scanf("%d%d%d",&n,&m,&r)){
for(int i=;i<=m;i++)
scanf("%d%d%d",&a[i].start,&a[i].end,&a[i].val);
sort(a+,a++m,cmp); int ans=;
//不重合的最大递增区间,类似最大递增子序列
for(int i=;i<=m;i++){
dp[i]=a[i].val;
for(int j=;j<i;j++){
if(a[j].end+r<=a[i].start){
dp[i]=max(dp[i],dp[j]+a[i].val);
}
}
ans=max(ans,dp[i]);
}
printf("%d\n",ans);
}
return ;
}

 

POJ 3616 Milking Time(最大递增子序列变形)的更多相关文章

  1. POJ 1836 Alignment 最长递增子序列(LIS)的变形

    大致题意:给出一队士兵的身高,一开始不是按身高排序的.要求最少的人出列,使原序列的士兵的身高先递增后递减. 求递增和递减不难想到递增子序列,要求最少的人出列,也就是原队列的人要最多. 1 2 3 4 ...

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

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

  3. poj 3616 Milking Time DP

    题意:在给予的N个时间里,奶牛Bessie在M个时间段里进行产奶,但是每次产奶后都要休息R个时间 M个时间段里,分别有开始时间start和结束时间end,和该时间段里产奶的效率efficiency 求 ...

  4. ACM: 强化训练-Beautiful People-最长递增子序列变形-DP

    199. Beautiful People time limit per test: 0.25 sec. memory limit per test: 65536 KB input: standard ...

  5. poj 3616 Milking Time (基础dp)

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

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

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

  7. poj 3616 Milking Time

                                                                                                 Milking ...

  8. poj 3616 Milking Time(dp)

    Description Bessie ≤ N ≤ ,,) hours (conveniently labeled ..N-) so that she produces as much milk as ...

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

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

随机推荐

  1. Unity3D手游开发日记(4) - 适合移动平台的热浪扭曲

    热浪扭曲效果的实现,分两部分,一是抓图,二是扭曲扰动.其中难点在于抓图的处理,网上的解决方案有两种,在移动平台都有很多问题,只好自己实现了一种新的方案,效果还不错. 网上方案1. 用GrabPass抓 ...

  2. [杂谈]ACM启程

    此处省略一大段传奇的经历. 只需要知道的是,现在再次开始使用本博客的唯一原因就是——我进大学有搞ACM的打算. 其实本来是没有的,受到某学长的指引和推荐,我觉得这条路在当前确切是绝对的优选. 2年没碰 ...

  3. 链接错误 multiply defined (by misc_1.o and misc.o).

    http://www.stmcu.org/module/forum/thread-286128-1-1.html *** Using Compiler 'V5.06 (build 20)', fold ...

  4. 用dom4j修改xml(增加修改节点)

    用dom4j修改xml(增加修改节点) 博客分类: Java XMLJavaMyeclipseServlet  使用dom4j修改解析xml,xml文件的位置是配置在xml.properties文件中 ...

  5. Calculating and saving space in PostgreSQL

    Q: I have a table in pg like so: CREATE TABLE t ( a BIGSERIAL NOT NULL, -- 8 b b SMALLINT, -- 2 b c ...

  6. [io benchmark]常用磁盘基准/压力测试工具

    Unix Disk I/O Benchmarks fio - NEW! fio is an I/O tool meant to be used both for benchmark and stres ...

  7. 为Azure Web Site 添加ADFS验证支持之二 在代码里使用ADFS

    下面我们来创建一个MVC 5.0的ASP.Net程序,并且将它部署到Azure Web Site上 通过Visual Studio 2015创建Web Project 在选择ASP.net模板的地方, ...

  8. mysql 自动记录数据插入及最后修改时间

    总结: `uptime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP 原文 应用场景: 1.在数据 ...

  9. oracle实用的sqlplus命令

    有时候难免没有工具,得自己手动输入sqlplus命令 执行SQL文件:@sql文件,例如:@/home/myuser/sql/test.sql查看数据库存在的存储过程:Select object_na ...

  10. 多例模式,保证实例的唯一性,仅适用于form窗体

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.W ...