题目链接

给出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. 用ul、li做横向导航

    /* ul li以横排显示 */ /* 所有class为menu的div中的ul样式 */ div.menu ul { list-style:none; /* 去掉ul前面的符号 */ margin: ...

  2. Oracle存储过程的一点使用总结

    [博客文章背景]博客开通已经1.2年了,一直碍于技术能力,不敢献丑.想起1年前在一个数据处理相关项目结束后,代金排主管让我做一个数据库开发总结文档和一个Toad.PL/SQL Developer工具的 ...

  3. TSF自定义候选词列表界面

    概述 TSF(Text Service Framework),已经取代IMM(Input Method Manager),成为win8+系统的输入法框架.现在有个需求,触摸屏上要使用软键盘(虚拟键盘, ...

  4. [Linked List]Swap Nodes in Pairs

    Total Accepted: 73777 Total Submissions: 219963 Difficulty: Medium Given a linked list, swap every t ...

  5. Pascal's Triangle,Pascal's Triangle II

    一.Pascal's Triangle Given numRows, generate the first numRows of Pascal's triangle. For example, giv ...

  6. Visual C++ 64bit应用程序项目设置

    Visual Studio 2005 This topic describes how to set up C++ applications to target 64-bit platforms us ...

  7. gcc 编译和链接

    1.现在对两个文件生成可执行文件 //thanks.c #include <stdio.h> int main(void) { printf("Hello World\n&quo ...

  8. 自定义HTTP错误页太小,导致显示默认友好错误页问题

    一 . 问题描述: chrome 向服务器发送构造字符串,返回错误页面如下 <html> <head> <title>404 Not Found</title ...

  9. Web学习

    http://book.2cto.com/201309/31936.html http://alvinalexander.com/ 查看锁表进程SQL语句1: select sess.sid,     ...

  10. C++ dynamic_cast实现原理

    dynamic_cast是一个操作符,其用法不再赘述.查看汇编码可以发现实际调用的是这个函数__RTDynamicCast,其内部实现如下: rtti.h: #pragma once extern & ...