UVA 10534 DP

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.