题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1950

题意:实际就是求最长递增子序列

题解:有两种解法,一种是利用二分,一种是用线段树

这个是这题的二分代码:

 #include <cstdio>
#include<algorithm>
#define F(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int N = 1e5+;
int a[N],d[N];
int LIS(int* a, int n, int* d){
int len=;d[]=a[];
F(i,,n)if(d[len]<a[i])d[++len]=a[i];
else d[lower_bound(d+,d++len,a[i])-d]=a[i];
return len;
}
int main(){
int t,n;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i =; i <=n; i++)scanf("%d",&a[i]);
printf("%d\n",LIS(a,n,d));
}
return ;
}
这个是求LIS的线段树的代码 #include<cstdio>
#include<algorithm>
#define root 1,n,1
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define F(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int N=1e5+;
int n,sum[N<<],a[N],ans,dp[N]; void update(int x,int k,int l,int r,int rt){
if(l==r){sum[rt]=k;return;}
int m=(l+r)>>;
if(x<=m)update(x,k,ls);
else update(x,k,rs);
sum[rt]=max(sum[rt<<],sum[rt<<|]);
} int query(int L,int R,int l,int r,int rt){
if(L<=l&&r<=R)return sum[rt];
int m=(l+r)>>,ret=;
if(L<=m)ret=max(ret,query(L,R,ls));
if(m<R)ret=max(ret,query(L,R,rs));
return ret;
} int main(){
while(~scanf("%d",&n)){
F(i,,n)scanf("%d",a+i),dp[i]=;
F(i,,(N<<)-)sum[i]=;ans=;
F(i,,n){
if(a[i]->){
dp[i]=max(dp[i],query(,a[i]-,root))+;
update(a[i],dp[i],root);
}else dp[i]=,update(a[i],dp[i],root);
ans=max(dp[i],ans);
}
printf("%d\n",ans);
}
return ;
}

hdu_1950_Bridging signals(LIS)的更多相关文章

  1. POJ 1631 Bridging signals (LIS:最长上升子序列)

    题意:给你一个长为n(n<=40000)的整数序列, 要你求出该序列的最长上升子序列LIS. 思路:要求(nlogn)解法 令g[i]==x表示当前遍历到的长度为i的所有最长上升子序列中的最小序 ...

  2. HDU 1950 Bridging signals(LIS)

    最长上升子序列(LIS)的典型变形,O(n^2)的动归会超时.LIS问题可以优化为nlogn的算法. 定义d[k]:长度为k的上升子序列的最末元素,若有多个长度为k的上升子序列,则记录最小的那个最末元 ...

  3. hdu----(1950)Bridging signals(最长递增子序列 (LIS) )

    Bridging signals Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  4. POJ 1631 Bridging signals(LIS O(nlogn)算法)

    Bridging signals Description 'Oh no, they've done it again', cries the chief designer at the Waferla ...

  5. hdoj 1950 Bridging signals【二分求最大上升子序列长度】【LIS】

    Bridging signals Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  6. POJ 1631 Bridging signals(LIS 二分法 高速方法)

    Language: Default Bridging signals Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 1076 ...

  7. B - Bridging signals (LIS)

    点击打开链接 B - Bridging signals 'Oh no, they've done it again', cries the chief designer at the Waferlan ...

  8. Poj 1631 Bridging signals(二分+DP 解 LIS)

    题意:题目很难懂,题意很简单,求最长递增子序列LIS. 分析:本题的最大数据40000,多个case.用基础的O(N^2)动态规划求解是超时,采用O(n*log2n)的二分查找加速的改进型DP后AC了 ...

  9. POJ 1631 Bridging signals(LIS的等价表述)

    把左边固定,看右边,要求线不相交,编号满足单调性,其实是LIS的等价表述. (如果编号是乱的也可以把它有序化就像Uva 10635 Prince and Princess那样 O(nlogn) #in ...

随机推荐

  1. apue学习记录——配置apue.3e,实现P4‘ls例子

    #include"apue.h" #include<dirent.h> int main(int argc,char *argv[]) { DIR *dp; struc ...

  2. redis13---事务处理。

    Jedis事务我们使用JDBC连接Mysql的时候,每次执行sql语句之前,都需要开启事务:在MyBatis中,也需要使用openSession()来获取session事务对象,来进行sql执行.查询 ...

  3. Sublime Text 3中配置运行Java

    1.安装JDK并配置环境变量 2.在JDK的bin目录下新建runJava.bat文件,右键选编辑,复制粘贴如下代码并保存: @echo off cd %~dp1 echo Compiling %~n ...

  4. (十二)this关键字

    ---摘自孤傲苍狼博客 一.this关键字 this是一个引用,它指向自身的这个对象. 看内存分析图:

  5. 自定义控件之圆形颜色渐变进度条--SweepGradient

    前几天在群里面有人找圆形可颜色渐变进度条,其中主要的知识点是SweepGradient: mSweepGradient = new SweepGradient(240, 360, new int[] ...

  6. UVa 1354 Mobile Computing | GOJ 1320 不加修饰的天平问题 (例题 7-7)

    传送门1(UVa): https://uva.onlinejudge.org/external/13/1354.pdf 传送门2(GOJ): http://acm.gdufe.edu.cn/Probl ...

  7. PostgreSQL AS不忽略大小写

    select p.name as Name from person p; as后的Name会显示为name,若想不忽略大小写,请把Name加上双引号 select p.name as "Na ...

  8. Effective JavaScript :第五章

    1.使用Object的直接实例构造轻量级的字典 字典就是可变长的字符串与值得映射集合.JavaScript甚至提供了枚举一个对象属性名的利器——for...in循环. var dict = { ali ...

  9. 自定义MVC框架(二) -基于XML文件

    1.oracle的脚本 create table STUDENT ( sid NUMBER primary key, sname ), age NUMBER, pwd ) ) create seque ...

  10. [SOJ] 1282. Computer games (KMP)

    坑爹题 1282. Computer Game Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description Brian is an ...