【题目链接】 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. 前端初学者——初探Modernizr.js Modernizr.js笔记

    什么是Modernizr? Modernizr 是一个用来检测浏览器功能支持情况的 JavaScript 库. 目前,通过检验浏览器对一系列测试的处理情况,Modernizr 可以检测18项 CSS3 ...

  2. [译]15-spring 自动装配

    前面的章节我们已经学习了如何使用bean元素在xml配置文件中声明一个bean.也学习了如何使用bean的子元素contructor-arg 和property进行bean的依赖项的注入. 之前bea ...

  3. shell之基本语法

    转:   read 命令从 stdin 获取输入并赋值给 PERSON 变量,最后在 stdout 上输出: #!/bin/bash # Script follows here: echo " ...

  4. 【bzoj1270】[BeijingWc2008]雷涛的小猫 dp

    题目描述   输入 输出 样例输入 样例输出 8 题解 dp 设f[i][j]表示在第i棵树的j高度时最多吃到的柿子数. 那么只有两种可能能够到达这个位置:滑下来.跳下来. 滑下来直接用f[i][j+ ...

  5. margin百分比,重叠和auto

    一. margin百分比 1. 普通元素的百分比margin都是相对于容器的宽度计算 2. 绝对定位元素的百分比margin是相对于第一个定位祖先元素(relative/absolute/fixed) ...

  6. linux安装图像界面

    http://jingyan.baidu.com/article/624e745957149734e8ba5a0e.html

  7. bzoj2693 莫比乌斯反演

    Description Hint T <= 10000N, M<=10000000   https://wenku.baidu.com/view/fbec9c63ba1aa8114431d ...

  8. Android 画笔Paint

    转自 http://wuxiaolong.me/2016/08/20/Paint/ 了解Android Paint,一篇就够.引用Aige<自定义控件其实很简单>系列博客的话“很多时候你压 ...

  9. 发布windows服务的批处理

    安装bat: C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe WatchWinService.exe pause 卸载bat ...

  10. [LeetCode]Word Search 回溯

    Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from l ...