zoj 2136 - Longest Ordered Subsequence

来源:互联网 发布:idman是什么软件 编辑:程序博客网 时间:2024/04/30 22:47

题目:最大上升子序列。

分析:dp,单调队列。点掉队列优化lis算法。

说明:(2011-09-19 01:36)。

#include <iostream>#include <cstdlib>using namespace std;int data[ 1002 ];int Queu[ 1002 ];int BS( int tail, int key ){    int l = 0,h = tail;    while ( l < h ) {        int m = (l+h)/2;        if ( Queu[ m ] > key )            h = m;        else l = m+1;    }    return l;}int main(){    int t,n;    while ( cin >> t )    while ( t -- ) {        cin >> n;        for ( int i = 1 ; i <= n ; ++ i )            cin >> data[ i ];                int tail = 0;        Queu[ 0 ] = data[ 1 ];        for ( int i = 2 ; i <= n ; ++ i )            if ( data[ i ] > Queu[ tail ] )                Queu[ ++ tail ] = data[ i ];            else Queu[ BS( tail, data[ i ] ) ] = data[ i ];                    cout << tail+1 << endl;        if ( t ) cout << endl;    }    return 0;}

0 0
原创粉丝点击