hdu5125 树状数组+dp
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
using namespace std;
const int maxn=;
int a[maxn],b[maxn];
int c[maxn][maxn*],h[maxn*],L;
int lowbit(int x){
return x&(-x);
}
void add(int loc, int floor,int v){
while(loc<=L){
c[floor][loc]=max(v,c[floor][loc]);
loc+=lowbit(loc);
}
}
int sum(int loc, int floor){
int ans=;
while(loc>){
ans=max(c[floor][loc],ans);
loc-=lowbit(loc);
}
return ans;
} int main()
{
int cas;
scanf("%d",&cas);
while(cas--){
int n,m;
scanf("%d%d",&n,&m);
L=;
for(int i=; i<n; ++i){
scanf("%d%d",&a[i],&b[i]);
h[L++]=a[i]; h[L++]=b[i];
}
memset(c,,sizeof(c));
sort(h,h+L);
L=unique(h,h+L)-h;
int ans=;
for(int i=; i<n; ++i){
int loca = lower_bound(h,h+L,a[i])-h+;
int locb = lower_bound(h,h+L,b[i])-h+;
int val;
for(int j=min(i+,m);j>; j--){
val = sum(loca-,j);
ans=max(ans,val+);
add(loca,j,val+);
val = sum(locb-,j-);
ans=max(ans,val+);
add(locb,j,val+);
}
val = sum(loca-,);
ans=max(ans,val+);
add(loca,,val+);
}
printf("%d\n",ans);
}
return ;
}
hdu5125 树状数组+dp的更多相关文章
- codeforces 597C (树状数组+DP)
题目链接:http://codeforces.com/contest/597/problem/C 思路:dp[i][j]表示长度为i,以j结尾的上升子序列,则有dp[i][j]= ∑dp[i-1][k ...
- hdu 4622 Reincarnation trie树+树状数组/dp
题意:给你一个字符串和m个询问,问你l,r这个区间内出现过多少字串. 连接:http://acm.hdu.edu.cn/showproblem.php?pid=4622 网上也有用后缀数组搞得. 思路 ...
- Codeforces 597C. Subsequences (树状数组+dp)
题目链接:http://codeforces.com/contest/597/problem/C 给你n和数(1~n各不同),问你长为k+1的上升自序列有多少. dp[i][j] 表示末尾数字为i 长 ...
- HDU2227Find the nondecreasing subsequences(树状数组+DP)
题目大意就是说帮你给出一个序列a,让你求出它的非递减序列有多少个. 设dp[i]表示以a[i]结尾的非递减子序列的个数,由题意我们可以写出状态转移方程: dp[i] = sum{dp[j] | 1&l ...
- CodeForces - 314C Sereja and Subsequences (树状数组+dp)
Sereja has a sequence that consists of n positive integers, a1, a2, ..., an. First Sereja took a pie ...
- HDU 6348 序列计数 (树状数组 + DP)
序列计数 Time Limit: 4500/4000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Subm ...
- [Codeforces261D]Maxim and Increasing Subsequence——树状数组+DP
题目链接: Codeforces261D 题目大意:$k$次询问,每次给出一个长度为$n$的序列$b$及$b$中的最大值$maxb$,构造出序列$a$为$t$个序列$b$连接而成,求$a$的最长上升子 ...
- 【XSY2727】Remove Dilworth定理 堆 树状数组 DP
题目描述 一个二维平面上有\(n\)个梯形,满足: 所有梯形的下底边在直线\(y=0\)上. 所有梯形的上底边在直线\(y=1\)上. 没有两个点的坐标相同. 你一次可以选择任意多个梯形,必须满足这些 ...
- hdu5489 树状数组+dp
2015-10-06 21:49:54 这题说的是个给了一个数组,然后删除任意起点的一个连续的L个数,然后求最长递增子序列<是递增,不是非递减>,用一个树状数组维护一下就ok了 #incl ...
随机推荐
- 转:ArcGIS API for JavaScript之图层
参考文章地址: https://developers.arcgis.com/javascript/3/jsapi/layer-amd.html Layer |–TiledMapServiceLayer ...
- 图->遍历
文字描述 从图中某一顶点出发遍历图中其余顶点,且使每一个顶点仅被访问一次,这一过程就叫图的遍历. 深度优先搜索:类似树的先根遍历:假设初始状态下,图中所有顶点都未曾被访问,则从某个顶点出发,访问此顶点 ...
- 添加linux系统调用的两种方式
原文:https://blog.csdn.net/sdulibh/article/details/51889279 向linux内核添加系统调用,一是通过编译内核添加,二是通过内核模块的方式添加: 一 ...
- 牛客网Wannafly挑战赛25A 因子 数论
正解:小学数学数论 解题报告: 传送门 大概会连着写几道相对而言比较简单的数学题,,,之后就会比较难了QAQ 所以这题相对而言还是比较水的,,, 首先这种题目不难想到分解质因数趴,, 于是就先对p和n ...
- 洛谷P3247 最小公倍数 [HNOI2016] 分块+并查集
正解:分块+并查集 解题报告: 传送门! 真的好神仙昂QAQ,,,完全想不出来,,,还是太菜了QAQ 首先还是要说下,这题可以用K-D Tree乱搞过去(数据结构是个好东西昂,,,要多学学QAQ),但 ...
- python实时得到鼠标的位置
1.#先下载pyautogui库,打开cmd输入pip install pyautogui,回车 2.代码如下: import os,time import pyautogui as pag try: ...
- echarts给数据视图添加表格样式
1,准备好样式 <style>.myTable {margin: 0 auto;/* height: 300px; */width: 700px;} .myTitle {backgroun ...
- mysql 1,2,3 关联查询出数字代表的具体意思
建表 TEST1 CREATE TABLE `TEST1` (`ID` int(11) NOT NULL,`IID` varchar(200) DEFAULT NULL,PRIMARY KEY (`I ...
- 阿里云RDS备份在本地mysql快速还原
本地准备: ##安装和RDS相同的mysql版本,拿mysql5.6为例 http://www.cnblogs.com/37yan/p/7513605.html ##安装Xtrabackup 包 cd ...
- rocketmq中的NettyRemotingClient类的简单分析
rocketmq中的NettyRemotingClient类的简单分析 Bootstrap handler = this.bootstrap.group(this.eventLoopGroupWork ...