【题目链接】 http://poj.org/problem?id=3171

【题目大意】

  给出一些区间和他们的价值,求覆盖一整条线段的最小代价

【题解】

  我们发现对区间右端点排序后有dp[r]=min(dp[l-1~r-1])+s
  而对于求最小值我们可以用线段树优化

【代码】

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <climits>
using namespace std;
const int N=100010;
int T[N*4],n,m,E,M,x,y;
struct data{int l,r,s;}p[N];
bool cmp(data a,data b){return a.r<b.r;}
int main(){
while(~scanf("%d%d%d",&n,&m,&E)){
E=E-m+2;
for(M=1;M<E;M<<=1);
fill(T,T+M+E+1,INT_MAX/2);
T[M+1]=0;
for(int i=0;i<n;i++){
scanf("%d%d%d",&p[i].l,&p[i].r,&p[i].s);
p[i].l=p[i].l-m+2;
p[i].r=p[i].r-m+2;
}sort(p,p+n,cmp);
for(int i=0;i<n;i++){
int t=INT_MAX/2;
x=p[i].l+M-2; y=p[i].r+M;
while(x^y^1>0){
if(~x&1)t=min(t,T[x+1]);
if(y&1)t=min(t,T[y-1]);
x>>=1;y>>=1;
}T[M+p[i].r]=min(T[M+p[i].r],t+p[i].s);
for(x=(M+p[i].r)/2;x;x/=2)T[x]=min(T[x<<1],T[(x<<1)^1]);
}printf("%d\n",T[E+M]==INT_MAX/2?-1:T[E+M]);
}return 0;
}

POJ 3171 Cleaning Shifts(DP+zkw线段树)的更多相关文章

  1. POJ 1769 Minimizing maximizer(DP+zkw线段树)

    [题目链接] http://poj.org/problem?id=1769 [题目大意] 给出一些排序器,能够将区间li到ri进行排序,排序器按一定顺序摆放 问在排序器顺序不变的情况下,一定能够将最大 ...

  2. [BZOJ1672][Usaco2005 Dec]Cleaning Shifts 清理牛棚 线段树优化DP

    链接 题意:给你一些区间,每个区间都有一个花费,求覆盖区间 \([S,T]\) 的最小花费 题解 先将区间排序 设 \(f[i]\) 表示决策到第 \(i\) 个区间,覆盖满 \(S\dots R[i ...

  3. poj 3171 Cleaning Shifts(区间的最小覆盖价值)

    Cleaning Shifts Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2743   Accepted: 955 De ...

  4. POJ 3171 Cleaning Shifts

    Description Farmer John's cows, pampered since birth, have reached new heights of fastidiousness. Th ...

  5. POJ 3264 Balanced Lineup(zkw线段树)

    [题目链接] http://poj.org/problem?id=3264 [题目大意] 求区间最大值和最小值的差值 [题解] 线段树维护区间极值即可 [代码] #include <cstdio ...

  6. 【POJ 2750】 Potted Flower(线段树套dp)

    [POJ 2750] Potted Flower(线段树套dp) Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4566   ...

  7. 【POJ3468】【zkw线段树】A Simple Problem with Integers

    Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. On ...

  8. 线段树(单标记+离散化+扫描线+双标记)+zkw线段树+权值线段树+主席树及一些例题

    “队列进出图上的方向 线段树区间修改求出总量 可持久留下的迹象 我们 俯身欣赏” ----<膜你抄>     线段树很早就会写了,但一直没有总结,所以偶尔重写又会懵逼,所以还是要总结一下. ...

  9. V-Parenthesis 前缀+ZKW线段树或RMQ

    Bobo has a balanced parenthesis sequence P=p 1 p 2…p n of length n and q questions. The i-th questio ...

随机推荐

  1. python之列表/元组/字典/字符串

    一.列表 格式:list = ['xxx','xxx','xxx'] 性质:可以修改列表内容 copy用法: import copy names = ['] names01 = names #直接引用 ...

  2. Leetcode 667.优美的排列II

    优美的排列II 给定两个整数 n 和 k,你需要实现一个数组,这个数组包含从 1 到 n 的 n 个不同整数,同时满足以下条件: ① 如果这个数组是 [a1, a2, a3, ... , an] ,那 ...

  3. CentOS下Apache虚拟主机配置

    通过phpinfo可以看到Apache安装的目录 修改配置文件,首先将配置文件备份 编辑httpd.conf,并找到虚拟路径配置的部分 vi httpd.conf 在vi下先按esc在键入 :/vho ...

  4. 爬虫:Scrapy7 - Scrapy终端(Scrapy shell)

    Scrapy 终端是一个交互终端,可以在未启动 spider 的情况下尝试及调试你的爬取代码.其本意是用来测试提取数据的代码,不过可以将其作为正常的 Python 终端,在上面测试任何 Python ...

  5. HDU 4288 Coder ( 离散化 + 离线 + 线段树 )

    这题跟ZOJ 3606的解题思路很相似. 题意:有3中操作:1.向集合中增加一个数x(1≤x≤1e9):2.从集合中删去一个数x(保证这个数存在):3.查询集合中所有位置满足i%5==3的数a[i]的 ...

  6. chrome浏览器console拓展用法

    chrome 浏览器console打印 使用CSS美化输出信息 console.log("%cThis will be formatted with large, blue text&quo ...

  7. 逆向映射是干嘛的anon_vma, vma, anon_vma_chain

    逆向映射是为了从page得到进程信息,里面有三个比较重要的结构体: mm_area_struct, anon_vma_chain, anon_vma 想象一种复杂的场景 所以其实一个进程对应着很多an ...

  8. 【bzoj4146】[AMPPZ2014]Divisors 数论

    原文地址:http://www.cnblogs.com/GXZlegend/p/6801411.html 题目描述 给定一个序列a[1],a[2],...,a[n].求满足i!=j且a[i]|a[j] ...

  9. linux下对/sys/class/gpio中的gpio的控制 (转)

        在嵌入式设备中对GPIO的操作是最基本的操作.一般的做法是写一个单独驱动程序,网上大多数的例子都是这样的.其实linux下面有一个通用的GPIO操作接口,那就是我要介绍的 “/sys/clas ...

  10. 《c程序设计语言》读书笔记-4.2-扩充atof函数

    #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> ...