BZOJ1109[POI2007] Stacked Wood klo*

Source: Internet
Author: User

BZOJ1109[POI2007] Stacked Wood klo

Test instructions

n number, the number of I is AI, now to remove some number, so that after the removal of the most digits in its corresponding position. The number of moves to be removed. n≤100000.

Exercises

DP equation: f[i]=f[j]+1 (I>j,a[i]>a[j],a[i]-a[j]>=i-j is A[i]-i>=a[j]-j), and the first constraint can be introduced by the latter two constraints, Therefore, it is possible to satisfy the third condition only if the second condition is satisfied, and this can be solved by the longest ascending subsequence sequence about a[i]-i] After the AI is sorted. This weakly used is a tree-like array (the number is inserted from small to large, each to the left of the F maximum of +1), the Complexity O (nlog2n). (I hear it's called a two-dimensional partial order)

Code:

1#include <cstdio>2#include <cstring>3#include <algorithm>4#include <queue>5 #defineInc (I,J,K) for (int i=j;i<=k;i++)6 #defineMAXN 1000107 #defineLB (x) x&-x8 using namespacestd;9 TenInlineintRead () { One     CharCh=getchar ();intf=1, x=0; A      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; Ch=GetChar ();} -      while(ch>='0'&&ch<='9') x=x*Ten+ch-'0', ch=GetChar (); -     returnf*x; the } - intN,c[maxn],ans,tot; pair<int,int>NDS[MAXN]; -InlinevoidAddintXintY) { while(x<=n) C[x]=max (c[x],y), x+=lb (x);} -InlineintQueryintx) {intq=0; while(x>=1) Q=max (Q,c[x]), x-=lb (x);returnq;} + intMain () { -N=read (); Inc (I,1, N) {intX=read ();if(i-x>=0) Nds[++tot]=make_pair (I-x,x);} +Sort (nds+1, nds+1+tot); AInc (I,1, tot) {intX=query (nds[i].second-1)+1; ans=Max (ans,x); add (nds[i].second,x);} atprintf"%d", ans);return 0; -}

20161031

BZOJ1109[POI2007] Stacked Wood klo*

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.