poj 1769 Minimizing maximizer 线段树维护dp
题目链接
给出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的更多相关文章
- POJ.1769.Minimizing maximizer(线段树 DP)
题目链接 /* 题意:有m个区间,问最少要多少个区间能覆盖[1,n] 注:区间要按原区间的顺序,不能用排序贪心做 设dp[i]表示最右端端点为i时的最小值 dp[e[i]]=min{dp[s[i]]~ ...
- Codeforces Round #271 (Div. 2) E题 Pillars(线段树维护DP)
题目地址:http://codeforces.com/contest/474/problem/E 第一次遇到这样的用线段树来维护DP的题目.ASC中也遇到过,当时也非常自然的想到了线段树维护DP,可是 ...
- codeforces Good bye 2016 E 线段树维护dp区间合并
codeforces Good bye 2016 E 线段树维护dp区间合并 题目大意:给你一个字符串,范围为‘0’~'9',定义一个ugly的串,即串中的子串不能有2016,但是一定要有2017,问 ...
- 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 ...
- POJ 1769 Minimizing maximizer(DP+zkw线段树)
[题目链接] http://poj.org/problem?id=1769 [题目大意] 给出一些排序器,能够将区间li到ri进行排序,排序器按一定顺序摆放 问在排序器顺序不变的情况下,一定能够将最大 ...
- Codeforces GYM 100114 D. Selection 线段树维护DP
D. Selection Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descriptio ...
- 【8.26校内测试】【重构树求直径】【BFS模拟】【线段树维护DP】
题目性质比较显然,相同颜色联通块可以合并成一个点,重新建树后,发现相邻两个点的颜色一定是不一样的. 然后发现,对于一条链来说,每次把一个点反色,实际上使点数少了2个.如下图 而如果一条链上面有分支,也 ...
- 2019牛客暑期多校训练营(第二场)E 线段树维护dp转移矩阵
题意 给一个\(n\times m\)的01矩阵,1代表有墙,否则没有,每一步可以从\(b[i][j]\)走到\(b[i+1][j]\),\(b[i][j-1]\),\(b[i][j+1]\),有两种 ...
- Codeforces750E. New Year and Old Subsequence (线段树维护DP)
题意:长为2e5的数字串 每次询问一个区间 求删掉最少几个字符使得区间有2017子序列 没有2016子序列 不合法输出-1 题解:dp i,p(0-4)表示第i个数匹配到2017的p位置删掉的最少数 ...
随机推荐
- 10Cookie
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- 使用XmlReader读Xml
XmlDocument和XElement在读取Xml时要将整个Xml文档放到内存中去操作,这样做操作简单,但是很费内存和IO(可能是磁盘IO或者网络IO):而在有些场景下我们必须考虑尽可能节省内存和I ...
- Java内部类总结
内部类是一种编译器现象,与虚拟机无关.编译器将会把内部类翻译成用美元符号$分隔外部类名与内部类名的常规类文件,而虚拟机对此一无所知.编译器为了引用外部类,生成了一个附加的实例域this$0 为什么要用 ...
- 泛型编程中的Concept, Model和Policy
A crude explanation Concept A set of requirements on a type, e.g. a RandomAccessible concept require ...
- mysql5 乱码问题解决方案
今天在写项目时碰到了mysql数据库数据乱码的问题,也从网上查了很多方法,前后折腾了两个小时才终于调整好.现在就把调整过程中碰到的一些问题记录下来: 1.项目是SSH架构,一开始我以为是调用hiber ...
- your local changes would be overwritten by merge. commit stash or revert them to proceed. view them
error log: your local changes would be overwritten by merge. commit stash or revert them to proceed. ...
- 收MUD巫师学徒,MUD开发,LPC语言开发
收MUD巫师学徒,MUD开发,LPC语言开发 对这个有兴趣的联系我,签订协议 Q 184377367
- IC卡、M1卡、CPU卡、SAM卡、PSAM卡的联系与区别
一. 技术方面(非接触式IC卡) 1. 逻辑加密卡又叫存储卡,卡内的集成电路具有加密逻辑和EEPROM(电可擦除可编程只读存储器). 2. CPU卡又叫智能卡,卡内的集成电路包括中央处理器(CPU ...
- [置顶] CSDN博客第四期移动开发最佳博主评选
CSDN博客第三期最佳移动开发博主评选圆满结束,恭喜所有上榜用户,为继续展示移动开发方向优秀博主,发掘潜力新星,为移动开发方向的博客用户提供平台,CSDN博客第四期移动开发最佳博主评选开始.同时,获奖 ...
- JavaEE Tutorials (20) - 企业应用安全入门
20.1企业应用的基本安全任务31620.2保护企业bean安全316 20.2.1使用声明式安全保护企业bean安全318 20.2.2通过编程方式保护企业bean安全321 20.2.3传播安全身 ...