链接

题意:给你一些区间,每个区间都有一个花费,求覆盖区间 \([S,T]\) 的最小花费

题解

先将区间排序

设 \(f[i]\) 表示决策到第 \(i\) 个区间,覆盖满 \(S\dots R[i]\) 的最小花费

显然 \(f[i]=\min_{R[j]\ge L[i]}f[j]+w[i]\)

按照区间建线段树,插右端点即可

#include<bits/stdc++.h>
#define REP(i,a,b) for(int i(a);i<=(b);++i)
using namespace std;
typedef long long ll;
inline int read(){char c;int w;
while(!isdigit(c=getchar()));w=c&15;
while(isdigit(c=getchar()))w=w*10+(c&15);return w;
}
inline char smax(int&x,const int&y){return x<y?x=y,1:0;}
inline char smin(ll&x,const ll&y){return x>y?x=y,1:0;}
const int N=100005;
struct data{int l,r,w;}a[N];
inline bool cmp(data x,data y){return x.r<y.r;}
int n,s,t;
ll minv[N<<2],f[N];
#define ls o<<1
#define rs o<<1|1
inline void ins(int o,int l,int r,int x,ll w){
smin(minv[o],w);if(l==r)return;int mid=l+r>>1;
x<=mid?ins(ls,l,mid,x,w):ins(rs,mid+1,r,x,w);
}
inline ll query(int o,int l,int r,int x,int y){
if(x>r||y<l)return minv[0];
if(x<=l&&r<=y)return minv[o];
int mid=l+r>>1;
return min(query(ls,l,mid,x,y),query(rs,mid+1,r,x,y));
}
int main(){
n=read(),s=read()+1,t=read()+1;
REP(i,1,n)a[i]=(data){read()+1,read()+1,read()};
sort(a+1,a+1+n,cmp);
memset(f,0x3f,sizeof f);memset(minv,0x3f,sizeof minv);
#define all 1,s-1,t
ins(all,s-1,0);f[s-1]=0;
REP(i,1,n)if(a[i].r>=s&&a[i].l<=t){
f[i]=query(all,max(s-1,a[i].l-1),min(a[i].r-1,t))+a[i].w;
ins(all,min(a[i].r,t),f[i]);
}
ll ans=minv[0];
for(int i=n;i;--i)if(a[i].r>=t){
smin(ans,f[i]);
}else break;
if(ans==minv[0])puts("-1");else cout<<ans;
return 0;
}

[BZOJ1672][Usaco2005 Dec]Cleaning Shifts 清理牛棚 线段树优化DP的更多相关文章

  1. BZOJ1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚

    1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 414  Solved: ...

  2. BZOJ_1672_[Usaco2005 Dec]Cleaning Shifts 清理牛棚_动态规划+线段树

    BZOJ_1672_[Usaco2005 Dec]Cleaning Shifts 清理牛棚_动态规划+线段树 题意:  约翰的奶牛们从小娇生惯养,她们无法容忍牛棚里的任何脏东西.约翰发现,如果要使这群 ...

  3. [Usaco2005 Dec]Cleaning Shifts 清理牛棚 (DP优化/线段树)

    [Usaco2005 Dec] Cleaning Shifts 清理牛棚 题目描述 Farmer John's cows, pampered since birth, have reached new ...

  4. BZOJ 1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚

    题目 1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚 Time Limit: 5 Sec  Memory Limit: 64 MB Description Farm ...

  5. P4644 [Usaco2005 Dec]Cleaning Shifts 清理牛棚

    P4644 [Usaco2005 Dec]Cleaning Shifts 清理牛棚 你有一段区间需要被覆盖(长度 <= 86,399) 现有 \(n \leq 10000\) 段小线段, 每段可 ...

  6. 【BZOJ1672】[Usaco2005 Dec]Cleaning Shifts 清理牛棚 动态规划

    [BZOJ1672][Usaco2005 Dec]Cleaning Shifts Description Farmer John's cows, pampered since birth, have ...

  7. [Usaco2005 Dec]Cleaning Shifts 清理牛棚

    题目描述 Farmer John's cows, pampered since birth, have reached new heights of fastidiousness. They now ...

  8. 【bzoj1672】[USACO2005 Dec]Cleaning Shifts 清理牛棚 dp/线段树

    题目描述 Farmer John's cows, pampered since birth, have reached new heights of fastidiousness. They now ...

  9. 【bzoj1672】[USACO2005 Dec]Cleaning Shifts 清理牛棚

    题目描述 Farmer John's cows, pampered since birth, have reached new heights of fastidiousness. They now ...

随机推荐

  1. EXPIREAT

    EXPIREAT key timestamp EXPIREAT 的作用和EXPIRE类似,都用于为key设置生存时间. 不同在于EXPIREAT命令接受都时间参数是UNIX时间戳(unix times ...

  2. ECNUOJ 2857 编辑距离

    编辑距离 Time Limit:5000MS Memory Limit:65536KBTotal Submit:314 Accepted:128 Description  有两个字符串(仅有英文小写字 ...

  3. [Poi] Build and Analyze Your JavaScript Bundles with Poi

    Ever wonder where those extra KB in your bundle are coming from? This lesson walks you through runni ...

  4. 移动端web app开发备忘

    近期要做个手机html5的页面,做些知识储备,重要的点记录下来以备兴许. 1.devicePixelRatio:定义设备物理象素和设备独立象素的比例.css中的px能够看作是设备的独立象素.通过dev ...

  5. Unity multiplayer

    using UnityEngine; using System.Collections; public class multiplayer_Button : MonoBehaviour { void ...

  6. 基于MVC4+EasyUI的Web开发框架经验总结(13)--DataGrid控件实现自己主动适应宽带高度

    在默认情况下,EasyUI的DataGrid好像都没有具备自己主动宽度的适应功能,通常是指定像素宽度的.可是使用的人员计算机的屏幕分辨率可能不一样,因此导致有些地方显示太大或者太小,总是不能达到好的预 ...

  7. Delphi新语法 For ..In

    首先我们要知道哪些类型可以用For In吧,下面就是: for Element in ArrayExpr do Stmt;      数组 for Element in StringExpr do S ...

  8. 换主页轮播的主题图片(4、删除)---轻开电子商务系统(企业入门级B2C站点)

    接(  换主页轮播的主题图片1 ) 文件:site/links/img0.html中的表单(第11行最后一个td) <td><if x="@{sys:canDo}" ...

  9. html2canvas截取页面

    1.下载html2canvas.js 2.引入 3.修改html2canvas支持远程图片处理 function ImageContainer(src, cors) { this.src = src; ...

  10. Git简介以及与SVN的区别

    Git是由著名Linux内核(Kernel)开发者LinusTorvalds为了便利维护Linux而开发的. Git是一个分布式的版本控制系统.作为一个分布式的版本控制系统,在Git中并不存在主库这样 ...