UVA - 10543 LIS

题意:见大白Page93
真没想到是两边分别设为终点和起点的LIS和..LDS?
注意,要求对称,所以分别取min

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#define rep(i,j,k) for(register int i=j;i<=k;i++)
#define rrep(i,j,k) for(register int i=j;i>=k;i--)
#define erep(i,u) for(register int i=head[u];~i;i=nxt[i])
#define iin(a) scanf("%d",&a)
#define lin(a) scanf("%lld",&a)
#define din(a) scanf("%lf",&a)
#define s0(a) scanf("%s",a)
#define s1(a) scanf("%s",a+1)
#define print(a) printf("%lld",(ll)a)
#define enter putchar('\n')
#define blank putchar(' ')
#define println(a) printf("%lld\n",(ll)a)
#define IOS ios::sync_with_stdio(0)
using namespace std;
const int maxn = 1e5+11;
const double eps = 1e-10;
typedef long long ll;
const int oo = 0x3f3f3f3f;
const double ERR = -2.3333;
ll read(){
    ll x=0,f=1;register char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int dp[maxn],a[maxn],n;
int dp2[maxn],b[maxn];
int tmp1[maxn],tmp2[maxn];
int main(){
    while(cin>>n){
        rep(i,1,n) b[i]=a[i]=read();
        reverse(b+1,b+1+n);
        memset(dp,0x3f,sizeof dp);
        memset(dp2,0x3f,sizeof dp2);
        rep(i,1,n){
            int pos=lower_bound(dp+1,dp+n,a[i])-dp;
            dp[pos]=a[i];
            tmp1[i]=pos;
        }
        rep(i,1,n){
            int pos=lower_bound(dp2+1,dp2+1+n,b[i])-dp2;
            dp2[pos]=b[i];
            tmp2[i]=pos;
        }
        int ans=-oo;
        rep(i,1,n){
            ans=max(min(tmp1[i],tmp2[n-i+1])*2-1,ans);
        }
        println(ans);
    }
    return 0;
}
posted @ 2018-03-17 19:29  Caturra  阅读(125)  评论(0编辑  收藏  举报