I. Introduction:
Luo Gu 1020 missile interceptors && 1223 wooden processing
Seeking does not increase the minimum number of divided sub-sequence;
Second, Theorem:
Dilworth Theorem: The Poset <A, ≤>, A provided the longest chain length is n, then the A elements into disjoint reverse strand, reverse strand number is at least n
May be considered: partial order concentrated totally ordered set minimum number equal to the length (number of elements) is the maximum reverse strand
Poset: " ≤ " is a number satisfying the set A is reflexive, anti-symmetric, transitive a binary relation, the <A, ≤ > is a poset
Full ordered set: For Poset <A, ≤ >, any of A, b∈A, A ≤b and B ≤A least one established
Reverse strand: two partial order for any centralized elements concerned, are not comparable
Having said that, this question of the use of means:
the smallest increase in the number of divisions is not equal to the longest sequence of sequence length rise
Third, the problem-solving
Therefore, the above problem can be solved by LIS (T2 can be sorted first as a key length)
But my LIS is this:
L[1]=1; for(int i=2;i<=n;i++){ L[i]=0; for(int j=1;j<i;j++) if(s[j]<s[i]) L[i]=max(L[i],L[j]); L[i]++; }
On the right, O (n- 2 ) DP;
How to optimize it?
Four, nlogn of LIS
It may be noted, for a number of x, increases the length len sequence s can "tolerate" the relationship between the size of its key elements and the end x s, if x is large, can be spliced together
With this discovery, we can maintain an array d, d [i] is stored at the end of rise of the current length i is the sub-sequence
For a number x, if it is larger than the current at the end of the longest sequence, will increase a maximum length;
Conversely, since d is a monotonically increasing, look for a large ratio x of the first end and replace it with x, known by the greedy This is correct and this step can be used to achieve upper_bound
d[1]=a[1]; for(int i=2;i<=n;i++){ if(a[i]>d[len]) d[++len]=a[i]; else{ int pos=upper_bound(d+1,d+1+n,a[i])-d; d[pos]=a[i]; } }
Annex: upper_bound lower_bound are bipartite and implemented, the former is the first large, which is greater than or equal to a first value if none is out of range