UVA 10534-wavio Sequence
Defines a sequence of Wavio. Its length is 2*n+1, the former n+1 strictly increment, after n+1 a strict decrement.
Find the longest Wavio subsequence in the given sequence. The output length.
In the LIS, we find the longest ascending subsequence length of each point at the end of the point P[i], and then reverse the LIS to find the longest descending subsequence length beginning with the point bit q[i].
Then enumerate the midpoint of the Wavio subsequence, the Wavio length of the store is 2 * min (P[i], q[i])-1;
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>Using namespace Std;constintINF =999999999;intNinta[10000+5];intdp[10000+5];intp[10000+5];intDQ[10000+5];int Q[10000+5];intMain () {Freopen ("OUT.txt","W", stdout); for(; scanf ("%d", &n) = =1;) { for(intI=0; i<n; i++) {scanf ("%d", &a[i]); } fill (Dp,dp+n,inf); for(intI=0; i<n;i++) {*lower_bound(Dp,dp+n,a[i]) = A[i]; P[i] = Lower_bound (Dp,dp+n,a[i])-DP +1; }Reverse(A, a+n); Fill (Dq,dq+n,inf); for(intI=0; i<n;i++) {*lower_bound(Dq,dq+n,a[i]) = A[i];Q[i]= Lower_bound (Dq,dq+n,a[i])-DQ +1; }Reverse(Q,Q+N);Reverse(A, a+n);intAns =1; for(intI=1; i<n-1; i++) {ans = max (ans,2*min(P[i],Q[i])-1); }printf("%d\ n", ans); }return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
UVA 10534 DP