题目链接

给出m个区间, 按区间给出的顺序, 求出覆盖$ [1, n] $ 至少需要多少个区间。

如果先给出[10, 20], 在给出[1, 10], 那么相当于[10, 20]这一段没有被覆盖。

令dp[i]表示覆盖[1, i]需要的区间数量。 那么有状态转移方程dp[i] = $ min[dp[i], dp[j] (s_k <= j < t_k)] + 1 $

然后求 \([s_k, t_k]\) 的最小值可以用线段树来求。 复杂度 $ m\log{n} $

感觉这个题的难度在于理解题意....

#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <complex>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, n, a) for(int i = a; i<n; i++)
#define fi first
#define se second
typedef complex <double> cmx;
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int mod = 1e9+7;
const int inf = 1061109567;
const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };
const int maxn = 5e4+5;
int minn[maxn<<2];
void update(int p, int val, int l, int r, int rt) {
if(l == r) {
minn[rt] = min(val, minn[rt]);
return ;
}
int m = l+r>>1;
if(p<=m)
update(p, val, lson);
else
update(p, val, rson);
minn[rt] = min(minn[rt<<1], minn[rt<<1|1]);
}
int query(int L, int R, int l, int r, int rt) {
if(L<=l&&R>=r) {
return minn[rt];
}
int m = l+r>>1, ret = inf;
if(L<=m)
ret = min(ret, query(L, R, lson));
if(R>m)
ret = min(ret, query(L, R, rson));
return ret;
}
int main()
{
int n, m, a, b, x;
while(~scanf("%d%d", &n, &m)) {
mem2(minn);
update(1, 0, 1, n, 1);
for(int i = 0; i < m; i++) {
scanf("%d%d", &a, &b);
int x = query(a, b-1, 1, n, 1);
update(b, x+1, 1, n, 1);
}
printf("%d\n", query(n, n, 1, n, 1));
}
return 0;
}

poj 1769 Minimizing maximizer 线段树维护dp的更多相关文章

  1. POJ.1769.Minimizing maximizer(线段树 DP)

    题目链接 /* 题意:有m个区间,问最少要多少个区间能覆盖[1,n] 注:区间要按原区间的顺序,不能用排序贪心做 设dp[i]表示最右端端点为i时的最小值 dp[e[i]]=min{dp[s[i]]~ ...

  2. Codeforces Round #271 (Div. 2) E题 Pillars(线段树维护DP)

    题目地址:http://codeforces.com/contest/474/problem/E 第一次遇到这样的用线段树来维护DP的题目.ASC中也遇到过,当时也非常自然的想到了线段树维护DP,可是 ...

  3. codeforces Good bye 2016 E 线段树维护dp区间合并

    codeforces Good bye 2016 E 线段树维护dp区间合并 题目大意:给你一个字符串,范围为‘0’~'9',定义一个ugly的串,即串中的子串不能有2016,但是一定要有2017,问 ...

  4. Codeforces Round #343 (Div. 2) D. Babaei and Birthday Cake 线段树维护dp

    D. Babaei and Birthday Cake 题目连接: http://www.codeforces.com/contest/629/problem/D Description As you ...

  5. POJ 1769 Minimizing maximizer(DP+zkw线段树)

    [题目链接] http://poj.org/problem?id=1769 [题目大意] 给出一些排序器,能够将区间li到ri进行排序,排序器按一定顺序摆放 问在排序器顺序不变的情况下,一定能够将最大 ...

  6. Codeforces GYM 100114 D. Selection 线段树维护DP

    D. Selection Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descriptio ...

  7. 【8.26校内测试】【重构树求直径】【BFS模拟】【线段树维护DP】

    题目性质比较显然,相同颜色联通块可以合并成一个点,重新建树后,发现相邻两个点的颜色一定是不一样的. 然后发现,对于一条链来说,每次把一个点反色,实际上使点数少了2个.如下图 而如果一条链上面有分支,也 ...

  8. 2019牛客暑期多校训练营(第二场)E 线段树维护dp转移矩阵

    题意 给一个\(n\times m\)的01矩阵,1代表有墙,否则没有,每一步可以从\(b[i][j]\)走到\(b[i+1][j]\),\(b[i][j-1]\),\(b[i][j+1]\),有两种 ...

  9. Codeforces750E. New Year and Old Subsequence (线段树维护DP)

    题意:长为2e5的数字串 每次询问一个区间 求删掉最少几个字符使得区间有2017子序列 没有2016子序列 不合法输出-1 题解:dp i,p(0-4)表示第i个数匹配到2017的p位置删掉的最少数 ...

随机推荐

  1. C# 几种退出程序的方式

    C# WinForm程序退出的方法 1.this.Close(); 只是关闭当前窗口,若不是主窗体的话,是无法退出程序的,另外若有托管线程(非主线程),也无法干净地退出: 2.Application. ...

  2. mysql性能优化学习笔记(2)如何发现有问题的sql

    一.使用mysql慢查询日志对有效率问题的sql进行监控      1)开启慢查询       show variables like ‘slow_query_log’;//查看是否开启慢查询日志   ...

  3. Laravel中的队列处理

    Laravel中的队列处理 队列介绍 为什么要有消息队?这里先对其进行一个简单的介绍,方便还不了解的同学理解.在面向对象里,有一个很简单的概念--消息传递,而消息队列就可以在它上面扩展一下,把它说的更 ...

  4. html5介绍

    html5与html4的区别   (h5 and h4)   什么是OPOA   1,    浏览器对h5的支持情况 2,    历史 --- h5         2004年,whatwg 提出 w ...

  5. chrome提供的功能

    chrome://chrome-urls/ List of Chrome URLs chrome://accessibility chrome://appcache-internals chrome: ...

  6. Delphi XE6调用javascript

    原文地址:Example of using JavaScript for Google maps in the Delphi XE6   XE6的TWebBrowser新增了EvaluateJavaS ...

  7. Java开发工具IntelliJ IDEA单元测试和代码覆盖率图解

    原文 http://www.cnblogs.com/xiongmaopanda/p/3314660.html Java开发工具IntelliJ IDEA使用教程:单元测试和代码覆盖率 本文将展示如何使 ...

  8. java--工具方法

    根据时间戳得到具体的时间: public static void main(String[] args) { SimpleDateFormat sdf = new SimpleDateFormat(& ...

  9. nexus 7 2013 驱动安装及root

    驱动安装 Nexus 7 2013连接上电脑后,设备管理器显示新设备 nexus 7 待安装驱动(其实是MTP设备待安装驱动).去谷歌网站下载最新的USB驱动,version 8.0 的.与以前的版本 ...

  10. Java类和对象初始化

    类的生命周期: Java类的初始化: 本阶段负责为类变量赋正确的初始值.(类变量即静态变量) Java编译器把所有的类变量初始化语句和静态初始化器通通收集到<clinit>方法中,该方法只 ...