链接

题意:给你一些区间,每个区间都有一个花费,求覆盖区间 \([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. 【Codeforces Round #423 (Div. 2) B】Black Square

    [Link]:http://codeforces.com/contest/828/problem/B [Description] 给你一个n*m的格子; 里面包含B和W两种颜色的格子; 让你在这个格子 ...

  2. Draw the RGB data from kinect C++ via opengl

    In order to improve my English writing skills,I am going to  write the blogs in English form now! -- ...

  3. 22.IntelliJ IDEA 切换 project

    转自:https://blog.csdn.net/qwdafedv/article/details/73838628?utm_source=blogxgwz0 1.file->open 2.选择 ...

  4. Python带括号的计算器

    带括号的计算器也是第一个自我感觉完成最好的 毕竟真的弄了一个多星期 虽然前期这路真的很难走  我会努力加油  将Python学好学踏实 参考了两位博主的文章 http://www.cnblogs.co ...

  5. 2015北京网络赛 G Boxes BFS+打表

    G Boxes 题意:n个位置摆有n个箱子,每次移动只能把相邻的垒起来,且上面的必须小于下面的.求摆成升序需要移动多少步. 思路:这里的n很小,只有7.但是bfs最快的情况需要2s左右,所以就打表了. ...

  6. ipad无法连接到app store怎么办

    之前入手的air2提示无法连接到app store:你需要首先更新系统到最新的ios版本,去通用设置里面,有个update software, 点击即可,然后才能用apple id 联入,否选择提示连 ...

  7. AtCoder Beginner Contest 067 D - Fennec VS. Snuke

    D - Fennec VS. Snuke Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement F ...

  8. SQLServer 查询最近一天,三天,一周,一月,一季度数据的方法

    三天 select * from T_news where datediff(day,addtime,getdate())<= 2 and datediff(day,addtime,getdat ...

  9. ZOJ 3175 Number of Containers 分块

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3216 乱搞的...watashi是分块做的...但我并不知道什么是分块...大 ...

  10. 昼猫笔记 JavaScript -- 面向对象(I)

    本文内容搬运自公众号 原文链接 本文主要内容:面向对象 预计阅读时间:6分钟 面向对象的方式 单例模式(字面量定义) var obj = {} 类的实例 var obj = new Object() ...