题目连接: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. C#语言之“String.Split”的使用【转】

    String.Split 方法有6个重载函数: 1) public string[] Split(params char[] separator) 2) public string[] Split(c ...

  2. 用两个栈实现队列,剑指offer P59

    public class QueueByStack { private Stack<Integer> stack1; private Stack<Integer> stack2 ...

  3. 如何设置linux的文件和目录的权限

    1 字符表示法 1)chmod [-R] 权限(mode)file   注:[-R]会将目录下所有权限都设置成指定的 who operator permission u(owner) +增加权限 r( ...

  4. wxWidgets显示视频

    wxWidgets中似乎没有专门用于显示视频的控件(虽然有wxWidgets本身的openGL控件wxGLCANVAS,但是我没有去试--) 按照这篇文章所讲的,从wxPanel继承出一个DrawPa ...

  5. 永洪BI配置测试及遇到的一些问题

    1.连oracle 11g数据库遇到密码不能验证通过. 在11g中, 数据库默认密码的大小写是敏感的,jdbc在给oracle密码时, 会将其变成大写.其他个别情况也会出现变成小写的. 为统一,去除o ...

  6. Android(对话框)

    一.消息对话框 所谓的消息对话框,就是说当你点击按钮弹框,它会弹出一个消息提示你,消息对话框有相应的确定.取消.其他按钮,比如下方: 代码: //消息提示框 public void testOne(V ...

  7. Arrar.prototype.map()的用法

    ---恢复内容开始--- map() 方法返回一个由原数组中的每个元素调用一个指定方法后的返回值组成的新数组. array.map(callback[, thisArg]) 注:[]在语法中[]内的内 ...

  8. MVC创建

    [1]创建ASP.NET_MVC应用程序   1>新建项目>web>Visual Studio 2012>ASP.NET MVC4 Web应用程序   2>填写名称,位置 ...

  9. HDU1009FatMouse' Trade(贪心)

    Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding th ...

  10. 设计新Xlator扩展GlusterFS[转]

    原文:http://www.linuxidc.com/Linux/2013-08/89105.htm 1. GlusterFS概述 GlusterFS是一个开源的分布式文件系统,具有强大的Scale- ...