HDU 1950 Bridging signals

 

http://acm.hdu.edu.cn/showproblem.php?pid=1950

和上一题基本一样,二分dp求LIS

ps:排名居然刷到第一了,原来从来没有遇到呢,好开心~

View Code
#include <iostream>

using namespace std ;

int dp[10001],p[40001];

int LIS(int n)

{

    int l,r,m,i,tail = 0;

    for ( dp[ ++ tail ] = p[ 1 ],i = 2 ; i <= n ; ++ i ) 

    {

        if ( dp[ tail ] <= p[ i ] ) 

        {

            dp[ ++ tail ] = p[ i ];

            continue;

        }

        for ( m=((r=tail)+(l=1)>>1) ; l < r ; m=(l+r)>>1 )

            if ( dp[ m ] <= p[ i ] ) l = m+1;

            else r = m;

        dp[ m ] = p[ i ];

    }

    return tail;

}

inline bool scan_d(int &num) 

{

        char in;bool IsN=false;

        in=getchar();

        if(in==EOF) return false;

        while(in!='-'&&(in<'0'||in>'9')) in=getchar();

        if(in=='-'){ IsN=true;num=0;}

        else num=in-'0';

        while(in=getchar(),in>='0'&&in<='9'){

                num*=10,num+=in-'0';

        }

        if(IsN) num=-num;

        return true;

}

int main()

{

    int t,n,nCase=1;

    scan_d(t);

    while(t--)

    {

        scan_d(n);

        for(int i=1;i<=n;i++)

        {

            int x;

            scan_d(x);

            p[i]=x;

        }

        int ans=LIS(n);

        printf("%d\n",ans);

    }

    return 0;

}

 

 

你可能感兴趣的:(Signal)