UVA 10534Wavio Sequence

Source: Internet
Author: User

Exercises

According to the Nlog (n) procedure of the longest ascending subsequence, the longest ascending subsequence at the end of each point is obtained.

And then, in turn, ask again.

Then take the minimum value * 2-1

Code:

#include <bits/stdc++.h>using namespacestd;#definePB Push_back#defineMP Make_pair#defineSe Second#defineFS First#defineLson l,m,rt<<1#defineRson m+1,r,rt<<1|1#definePII pair<int,int>Const intINF =1000000000;Const intMAXN =10050;Const intM =4000;intN;inta[MAXN], b[MAXN];intnum[maxn],num2[MAXN];intBsintSintEintx) {    intL = s, r = e, Goal = e +1;  while(L <=r) {intm = (L + r) >>1; if(b[m] >=x) {goal=m; R= M-1; }        ElseL = m +1; }    returngoal;}intMain () {intN;  while(~SCANF ("%d", &N)) { for(inti =1; I <= N; i + +) scanf ("%d", &a[i]); intTMP =1; b[TMP]=a[TMP]; num[TMP]=1;  for(inti =2; I <= N; i + + )        {            intPOS =bs (1, TMP, a[i]); b[POS]=a[i]; num[i]=POS; if(pos = = tmp +1) TMP + +; } reverse (a+1, A + n +1 ); TMP=1; b[TMP]=a[TMP]; num2[TMP]=1;  for(inti =2; I <= N; i + + )        {            intPOS =bs (1, TMP, a[i]); b[POS]=a[i]; num2[i]=POS; if(pos = = tmp +1) TMP + +; }        intG =0;  for(inti =1; I <= N; i + +) G = max (g, Min (num[i], num2[n +1-i]) *2-1 ); printf ("%d\n", G); }    return 0;}

UVA 10534Wavio Sequence

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.