标签:name set nbsp memset style space 反向 href net
UVa 10534 Wavio Sequence
链接:https://vjudge.net/problem/UVA-10534
分别列出每个数列的最长上升子序列(LIS)和最长下降子序列(LDS)
#include <bits/stdc++.h> using namespace std; const int N=10000+10; int a[N],dp[N], lis[N],lds[N]; int main() { int n; while (scanf("%d", &n) != EOF){ for (int i=0;i<n;i++) scanf("%d",&a[i]); memset(dp,0,sizeof(dp)); int pos=0; dp[0]=a[0];lis[0]=0; for(int i=1; i<n; i++) { if(a[i]>dp[pos]) dp[++pos] = a[i]; else dp[lower_bound(dp,dp+pos+1,a[i])-dp]=a[i]; lis[i]=pos; } memset(dp,0,sizeof(dp)); pos=0; dp[0]=a[n-1];lds[n-1]=0; for(int i=n-1; i>=0; i--) { if(a[i]>dp[pos]) dp[++pos] = a[i]; else dp[lower_bound(dp,dp+pos+1,a[i])-dp]=a[i]; lds[i]=pos; } int ans=0; for (int i=0;i<n;i++) ans=max(ans,min(lis[i],lds[i])); printf("%d\n",ans*2+1); } return 0; }
标签:name set nbsp memset style space 反向 href net
原文地址:https://www.cnblogs.com/chillilly/p/12732975.html