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*