【题目链接】 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. 小红帽安装centos的yum的一些坑!

    [root@localhost ~]# lsanaconda-ks.cfg yum-3.4.3-158.el7.centos.noarch.rpm yum-updateonboot-1.1.31-45 ...

  2. 孤荷凌寒自学python第四十三天python 的线程同步之Queue对象

     孤荷凌寒自学python第四十三天python的线程同步之Queue对象 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) Queue对象是直接操作队列池的对象,队列中可以存放多种对象,当然也 ...

  3. Anaconda基本使用

    anaconda常用使用命令 显示安装程序包列表 conda list 选择其它的源 conda config --add channels https://mirrors.tuna.tsinghua ...

  4. Leetcode with Python -> Sort

    349. Intersection of Two Arrays Given two arrays, write a function to compute their intersection. Ex ...

  5. HDU 4671 Backup Plan 构造

    负载是否平衡只与前两列有关,剩下的只要与前两列不重复就随便放. 第一列我们按1-n这样循环放,第二列每次找个数最少的那个服务器放. #include <cstdio> #include & ...

  6. Hexo博客收录百度和谷歌-基于Next主题

    Hexo博客收录百度和谷歌-基于Next主题(应该是比较全面的一篇教程) 我们的博客做出来当然是希望别人来访问,但是Github和Coding都做了防爬虫处理,这样子我们博客可能就无法被搜索引擎收录, ...

  7. hdu 2141 Can you find it? (二分法)

    Can you find it? Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/10000 K (Java/Others ...

  8. [poj] 1066 Treasure Hunt || 判断直线相交

    原题 在金字塔内有一个宝藏p(x,y),现在要取出这个宝藏. 在金字塔内有许多墙,为了进入宝藏所在的房间必须把墙炸开,但是炸墙只能炸每个房间墙的中点. 求将宝藏运出城堡所需要的最小炸墙数. 判断点和直 ...

  9. bzoj 4407 于神之怒加强版 (反演+线性筛)

    于神之怒加强版 Time Limit: 80 Sec  Memory Limit: 512 MBSubmit: 1184  Solved: 535[Submit][Status][Discuss] D ...

  10. NOIP 2016 提高组 复赛 Day2T1==洛谷2822 组合数问题

    题目描述 组合数表示的是从n个物品中选出m个物品的方案数.举个例子,从(1,2,3) 三个物品中选择两个物品可以有(1,2),(1,3),(2,3)这三种选择方法.根据组合数的定 义,我们可以给出计算 ...