Ultraviolet A 111-history grading

Source: Internet
Author: User

Http://uva.onlinejudge.org/index.php? Option = com_onlinejudge & Itemid = 8 & category = 114 & page = show_problem & problem = 47

 

Question: Judge two orders
).

 

Question type: simple DP, Longest Common subsequence, longest single-incrementing subsequence. (Note the differences between strings and sequences)

 

Analysis: solution 1: The sort sequence becomes the longest common substring between the sequence and the original sequence.



Solution 2: Follow the longest single-incrementing subsequence, and finally change to the maximum value of D.

 

Code:

In addition, this question is quite problematic. Take a look at the second example and you will know that, relying on it, I was depressed for one night and wiped it.


Decisive contempt.

 

 

 

 

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

It's not good tonight.

 

The following analysis is reproduced to Daniel:

 

Author: Wang yuyun

Http://www.cnblogs.com/devymex/archive/2010/08/10/1796560.html

 

Analysis

Note that the given sequence is different from the general order of appearance. For example, 4, 2, 3, 1, 4th events are generally in 1st bits, 2nd events are in 2nd bits, and 1st events are in 4th bits. However, in this question, the meaning of the sequence is that 1st events are in 4th bits, 2nd events are in 2nd bits, and 4th events are in the first place. To facilitate calculation, You need to convert the input sequence so that the number is seated. For example, the correct sequence is:

Correct answer student answer meaning
Input sequence 3 1 2 4 9 5 10 6 8 72 10 1 3 8 4 9 5 7 6 historical events occur in the nth Digit
The converted sequence 2 3 1 4 6 8 10 9 5 73 1 4 6 8 10 9 5 7 2 has several historical events

Next we will use the converted sequence for calculation. To make it easy to see whether the student's answer sequence is correct, the student's answer should be converted according to the correspondence between the correct answer and 1 2... 10. In the correct answer, 2nd historical events occur in 1st digits, SO 2 in the student's answer should be converted to 1; 3 to 2, and so on. The student answer is converted to the final sequence:

1 2 3 4 5 6 7 8 9 10
Sequence 2 3 4 5 6 7 8 9 10 1

Obviously, the length of the longest ordered substring (non-sequential) of this sequence is 9. It is very troublesome to convert the correct answer sequence and the student answer sequence in sequence. In fact, the correct answer sequence does not need to be converted. Assume that the correct answer sequence is a and the student answer sequence is B, then the final position of the historical event that occurs in the bits is Ai. In this way, all conversions can be completed at one time.

The next step is to find the longest ordered substring. Because the correct sequence is from small to large, the examples are started from the last one. Find the longest ordered sub-String Length MI after each number (including itself), and then find the maximum value in the most Mi, that is, the solution. View the following sequence:

1 2 3 4 5 6 7 8 9 10
Sequence 5 8 3 7 6 1 9 2 10 4

 

Over

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.