https://vjudge.net/problem/POJ-3616

猛刷简单dp的第一天第二题。

这道题乍一看跟背包很像,不同的在于它是一个区间,背包是定点,试了很久想往背包上套,都没成功。

这题的思路感觉有点陌生,又有点类似于求最长不降子序列的题。

dp[i]为到第i个区间为止(该区间肯定有i)的最大挤奶量,最后从m个里面取最大。

 #include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stack>
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define INF 0x3f3f3f3f
typedef unsigned long long ll;
using namespace std;
struct Node{
int from, to, w;
}node[];
int dp[];
bool cmp(const Node a, const Node b)
{
return a.to < b.to;
}
int main()
{
int n, m, r;
cin >> n >> m >> r;
for(int i = ; i < m; i++){
cin >> node[i].from >> node[i].to >> node[i].w;
}
memset(dp, , sizeof(dp));
sort(node, node+m, cmp);//按结束时间升序
for(int i = ; i < m; i++){
dp[i] = node[i].w;
for(int j = ; j < i; j++){
if(node[i].from >= node[j].to+r){
dp[i] = max(dp[i], dp[j]+node[i].w);//人人为我
}
}
}
int maxm = -INF;
for(int i = ; i < m; i++){
maxm = max(maxm, dp[i]);
}
cout << maxm << endl;
return ;
}

poj3616 Milking Time(状态转移方程,类似LIS)的更多相关文章

  1. 动态规划 POJ3616 Milking Time

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

  2. hdu 动态规划(46道题目)倾情奉献~ 【只提供思路与状态转移方程】(转)

    HDU 动态规划(46道题目)倾情奉献~ [只提供思路与状态转移方程] Robberies http://acm.hdu.edu.cn/showproblem.php?pid=2955      背包 ...

  3. 【转载】 HDU 动态规划46题【只提供思路与状态转移方程】

    1.Robberies 连接 :http://acm.hdu.edu.cn/showproblem.php?pid=2955      背包;第一次做的时候把概率当做背包(放大100000倍化为整数) ...

  4. Mark一下, dp状态转移方程写对,可是写代码都错,poj 1651 poj 1179

    dp题: 1.写状态转移方程; 2.考虑初始化边界,有意义的赋定值.还没计算的赋边界值: 3.怎么写代码自底向上计算最优值 今天做了几个基础dp,所有是dp方程写对可是初始化以及计算写错 先是poj ...

  5. 简单dp的状态转移方程集合

    1.对于任一种N的排列A,定义它的E值为序列中满足A[i]>i的数的个数.给定N和K(K<=N<=1000),问N的排列中E值为K的个数. dp[i][j]表示i个数的排列中E值为j ...

  6. POJ3616 Milking Time —— DP

    题目链接:http://poj.org/problem?id=3616 Milking Time Time Limit: 1000MS   Memory Limit: 65536K Total Sub ...

  7. poj2385 Apple Catching(dp状态转移方程推导)

    https://vjudge.net/problem/POJ-2385 猛刷简单dp的第一天的第一题. 状态:dp[i][j]表示第i秒移动j次所得的最大苹果数.关键要想到移动j次,根据j的奇偶判断人 ...

  8. POJ3616 Milking Time【dp】

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

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

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

随机推荐

  1. 2. ELK 之kibana 简介、获取、安装

    简介 kibana是什么?简单理解就是一种可视化工具,比如日志记录之后的可视化操作工具,支持 折线图,饼状图,表格等,支持按时间维度等自定义维度角度 数据搜索.分析等等. 2.   获取 https: ...

  2. Linux read line

    cat ./port_list|while read linedo done

  3. python对象、引用

    1.python对象 python中 所有的python对象都有3个特征: 身份,类型和值 身份: 每个对象有一个唯一的身份标识自己,这个值可以被认为是该对象内存地址.id()查看. 类型 type( ...

  4. C#基础:委托之Action<T>和Func<T>的用法

  5. POJ 1979 红与黑

    题目地址: http://poj.org/problem?id=1979  或者  https://vjudge.net/problem/OpenJ_Bailian-2816 Red and Blac ...

  6. c#中的委託,匿名方法和lambda表達式

    (原博)http://www.cnblogs.com/niyw/archive/2010/10/07/1845232.html 简介 在.NET中,委托,匿名方法和Lambda表达式很容易发生混淆.我 ...

  7. scrapy 手动编写模板

    import scrapy class Tzspider(scrapy.Spider): # spider的名字,唯一 name = 'tz' # 初始url列表 start_urls = ['htt ...

  8. python自带线程池

    1. 注意: 导包是: from multiprocessing.pool import ThreadPool #线程池不在thrading中 2. 代码: from mutiprocessing.p ...

  9. ubuntu中git

    1.在ubuntu中安装git $ sudo apt-get install git git-core 2.配置本机的git $ git config --global user.name " ...

  10. SVM—PK—BP:SVR(better)和BP两种方法比较且实现建筑物钢筋混凝土抗压强度预测—Jason niu

    load concrete_data.mat n = randperm(size(attributes,2)); p_train = attributes(:,n(1:80))'; t_train = ...