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

本文介绍了一种解决最长递增子序列(LIS)问题的有效算法,并通过一个具体实例展示了如何利用该算法来求解。文章提供的代码实现了O(nlogn)的时间复杂度,适用于处理大规模数据集。

把左边固定,看右边,要求线不相交,编号满足单调性,其实是LIS的等价表述。

(如果编号是乱的也可以把它有序化就像Uva 10635 Prince and Princess那样

O(nlogn)

#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
//#include<bits/stdc++.h>
using namespace std;

const int maxn = 4e4+5;
int g[maxn];

//#define LOCAL
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    int T; cin>>T;
    while(T--){
        int n, ans = 0; scanf("%d",&n);
        for(int i = 0,c = 1; i < n; i++){
            int x, k; scanf("%d",&x);
            k = lower_bound(g+1,g+c,x)-g;
            ans = max(ans,k);
            g[k] = x;
            if(k==c) c++; //不用把辅助数组g初始化,只要维护一个下标即可
        }
        printf("%d\n",ans);
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/jerryRey/p/4887319.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值