The maximum increment sub-sequence problem of algorithm note (Russian czar question)

Source: Internet
Author: User

1. Given a n*2 two-bit array, as a two-tuple, for example [[A1,B1],[A2,B2],[A3],[B3]], the provisions: a If you want to put a two-tuple in a two-tuple B, a value in a must be greater than the value of a, a must be greater than the B value in B. If you choose a two-tuple in a two-dimensional array, can the two-tuple be placed in a few layers?

For example: [[5,4],[6,4],[6,7],[2,3]], the maximum number can be placed on 3 layers, [2,3]=>[5,4]=>[6,7]

Requirements: Implementation of time Complexity O (N*LOGN) solution

Analytical:

Algorithm prototype: Maximum increment sub-sequence problem: 2.1.6.4.5.2.7.4 longest increment subsequence is 1.4.5.7 can not be scrambled in order, longest length

O (n^2): Generate auxiliary array h[i] as long as the original array, h[0] to contain only array[0] when the length of the longest increment subsequence, h[0] is 1, h[1] is 0, h[2] is [2] .... I'm going to have to enumerate all the values before I get the value of the position.

O (N*LOGN): Generate auxiliary array h[i] as long as the original array, h[0] position will be 2 copy into, set h[0] as a valid area, followed by an invalid zone, in the active area, when encountered 1 o'clock, the 2 is rewritten to 1, the longest increment subsequence ending with 1 is 1, encounters 6, find the first number greater than 6, is not found, the active area extends one position to the right

This time the effective area is 1,6. Next find 4, found that the effective area of 6:4 large, then replace. The effective zone is 2. Hit 5, effective zone right extension, effective area is 1,4,5. (The process of filling in a valid area is binary) and so on, the maximum length of the longest increment subsequence ending with 7 is 4. The maximum length ending with 4 is 3. Returns the maximum value that occurs with a global variable record.

The second method, H[i], means the smallest end of the longest incrementing subarray that traverses the length of i+1 to the current time.

Solve the problem: first a small to large sort, on this basis, then B from small to large sorting so that can not use O (N*LOGN) Two-point search method to accelerate!!

Optimal solution: Sort by the value of a first from small to large, and then B from large to small in the same value as a

Build auxiliary array H[i], the array does not put a two-tuple, the array of two tuples in the value of B appears. Then follow the prototype method 2 above to sort.

----from the Cow parlour algorithm explaining live lecture

seconds, whoa! I get it!

Sorry, the next specific process does not say, too wonderful, has been wonderful to rely on the brain to fill the next process!

--------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------

In the end I still didn't!

It won't come true!

This is still the first question!

Do not do algorithmic engineers after the kill!

The maximum increment sub-sequence problem of algorithm note (Russian czar question)

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.