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