链接

题意:给你一些区间,每个区间都有一个花费,求覆盖区间 \([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. HDU 4889 Scary Path Finding Algorithm

    其实这个题是抄的题解啦…… 题解给了一个图,按照那个图模拟一遍大概就能理解了. 题意: 有一段程序,给你一个C值(程序中某常量),让你构造一组数据,使程序输出"doge" 那段代码 ...

  2. 【BZOJ 1051】[HAOI2006]受欢迎的牛

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] Tarjan算法强连通缩点 . 最后出度为0的点. 如果只有一个. 那么这个"大点"所包含的点的个数就是答案了. ...

  3. codevs——T2806 红与黑

    http://codevs.cn/problem/2806/  时间限制: 1 s  空间限制: 64000 KB  题目等级 : 白银 Silver 题解       题目描述 Descriptio ...

  4. Codeforces Round #313 (Div. 2) 解题报告

    A. Currency System in Geraldion: 题意:有n中不同面额的纸币,问用这些纸币所不能加和到的值的最小值. 思路:显然假设这些纸币的最小钱为1的话,它就能够组成随意面额. 假 ...

  5. resin后台输出中文乱码的解决的方法!

    近期从tomcat移植到resin,发现这东西不错啊! 仅仅是后台输出时有时候中文会乱码. 如今找到resin后台输出中文乱码的解决的方法: 编辑conf/resin.con文件: <!--ja ...

  6. 百度地图SDK for Android【Demo兴趣点搜索】

            百度地图SDK为开发人员提供了便捷的检索服务. 今天我将为大家介绍Poi检索相关的内容. 首先,我们要构建一个最主要的地图应用.详细介绍请參考:百度地图SDK for Android[ ...

  7. POJ 3263 差分+set判重

    题意: 思路: 对于每一个区间 [a,b] [a+1,b-1]肯定是比a,b低至少1的 因为题目要求最大值 所以就直接差分一下 搞之 (复杂度 O(n)) Discuss里说有重复的数据 用set判一 ...

  8. C++ BigInteger模板

    #include <cstdio> #include <cstring> #include <string> #include <iostream> # ...

  9. Vue 全局过滤和局部过滤

    局部过滤器(放在组件里) filters: { //局部过滤器 FormattingMoney:value=>{ return value==null? '0' : value/100 } }, ...

  10. 基于Pipe的PureMVC FLEX框架的多核共享消息技术

    pipes utilities,也就是所谓的通道(管道),为什么要使用通道呢?模块的结构都是一个单独的puremvc结构,模块和模块,shell和模块之间的通信 不能使用puremvc中的消息进行,因 ...