zoukankan      html  css  js  c++  java
  • UVA-10534 (LIS)

    题意:

    给定一个长为n的序列,求一个最长子序列,使得该序列的长度为2*k+1,前k+1个数严格递增,后k+1个数严格单调递减;

    思路:

    可以先求该序列最长单调递增和方向单调递增的最长序列,然后枚举那第k+1个数更新答案就好了;

    AC代码:

    /************************************************ 
    ┆  ┏┓   ┏┓ ┆    
    ┆┏┛┻━━━┛┻┓ ┆ 
    ┆┃       ┃ ┆ 
    ┆┃   ━   ┃ ┆ 
    ┆┃ ┳┛ ┗┳ ┃ ┆ 
    ┆┃       ┃ ┆  
    ┆┃   ┻   ┃ ┆ 
    ┆┗━┓    ┏━┛ ┆ 
    ┆  ┃    ┃  ┆       
    ┆  ┃    ┗━━━┓ ┆ 
    ┆  ┃  AC代马   ┣┓┆ 
    ┆  ┃           ┏┛┆ 
    ┆  ┗┓┓┏━┳┓┏┛ ┆ 
    ┆   ┃┫┫ ┃┫┫ ┆ 
    ┆   ┗┻┛ ┗┻┛ ┆       
    ************************************************ */  
    
    
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <bits/stdc++.h>
    #include <stack>
    
    using namespace std;
    
    #define For(i,j,n) for(int i=j;i<=n;i++)
    #define mst(ss,b) memset(ss,b,sizeof(ss));
    
    typedef  long long LL;
    
    template<class T> void read(T&num) {
        char CH; bool F=false;
        for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
        for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
        F && (num=-num);
    }
    int stk[70], tp;
    template<class T> inline void print(T p) {
        if(!p) { puts("0"); return; }
        while(p) stk[++ tp] = p%10, p/=10;
        while(tp) putchar(stk[tp--] + '0');
        putchar('
    ');
    }
    
    const LL mod=20071027;
    const double PI=acos(-1.0);
    const int inf=1e9;
    const int N=1e4+100;
    const int maxn=(1<<8);
    const double eps=1e-8;
    
    int a[N],g[N],pre[N],nex[N],n;
    
    inline void Init()
    {
        For(i,1,n)g[i]=inf;
    }
    int main()
    {       
            while(cin>>n)
            {
                For(i,1,n)read(a[i]);
                Init();
                For(i,1,n)
                {
                    int temp=lower_bound(g+1,g+n+1,a[i])-g;
                    pre[i]=temp;
                    g[temp]=a[i];
                }
                Init();
                for(int i=n;i>0;i--)
                {
                    int temp=lower_bound(g+1,g+n+1,a[i])-g;
                    nex[i]=temp;
                    g[temp]=a[i];
                }
                int ans=0;
                For(i,1,n)
                {
                    int temp=min(pre[i],nex[i]);
                    ans=max(ans,2*temp-1);
                }
                cout<<ans<<"
    ";
            }
            return 0;
    }
    

      

  • 相关阅读:
    Leetcode No.121
    Leetcode No.97 ***
    (描述需要改进) Leetcode No.71 **
    (描述需要改进)Leetcode No.68 **
    Leetcode No.72 ***
    【笔记】存储位置/修改表/字符集.【3(完结创建表)】
    redis 事件驱动模型解析
    redis 官网文档学习笔记 简单翻译
    redis 官网文档 sentinel 简单翻译 && 简单总结QA
    redis 学习笔记 总
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5717648.html
Copyright © 2011-2022 走看看