您的位置:首页 > 其它

poj 1631(Bridging signals LIS)nlogn

2013-08-26 16:36 507 查看
题目链接:点击打开链接

题目大意:绕了这么多圈子,其实还是求最长上升子序列

题目分析:用nlog n

与 poj2533一样啊:点击打开链接

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
const int maxn=40005;
int stack[maxn];
int main()
{
    freopen("out.txt","w",stdout);
    freopen("in.txt","r",stdin);
    int n,i,top,data,j,p;
    scanf("%d",&n);
    while(n--)
    {
        scanf("%d",&p);
        top=0;stack[0]=-1;
        for(i=0;i<p;i++)
        {
            scanf("%d",&data);
            if(data>stack[top]) stack[++top]=data;
            else
            {
                int l=1,r=top,mid;
                while(l<=r)
                {
                   mid=(l+r)/2;
                   if(data>stack[mid])  l=mid+1;
                   else  r=mid-1;
                }
                stack[l]=data;
            }
        }
        printf("%d\n",top);
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: