zoukankan      html  css  js  c++  java
  • POJ 1631 Bridging signals(LIS的等价表述)

    把左边固定,看右边,要求线不相交,编号满足单调性,其实是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
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    类加载器
    类加载器
    类加载器
    类加载器
    Java11新特性
    Java11新特性
    Spring Cloud Alibaba学习笔记(24)
    Java11新特性
    PyCharm Professional 2016.1 破解 激活
    pycharm最新激活码 2018 2.28 到期
  • 原文地址:https://www.cnblogs.com/jerryRey/p/4887319.html
Copyright © 2011-2022 走看看