Pku acm 1887 testing the catcher dynamic problem solving report (11)

Source: Internet
Author: User

Http://acm.pku.edu.cn/JudgeOnline/problem? Id = 1887

The topic description is complex. In fact, it is to find the longest descent subsequence, which is also a typical topic of dynamic planning. There are two algorithms for this type of problem: T (o) = O (N ^ 2), and T (o) = O (nlogn). Here we use the first one, the second type is described in the 1631 bridging signals solution report.

Create a one-dimensional array num_array [J], max_array [], num_array [J] to indicate the sequence elements, max_array [I] indicates the longest descent subsequence in the sequence ending with element I, initialized as 1. For a max_array [I], traverse each element J, if num_array [J]> num_array [I] And max_array [J]> = max_array [I], 1 is required for max_array [J], so the recurrence formula is:

If (num_array [I] <= num_array [J] & max_array [I] <= max_array [J])

Max_array [I] ++;

The largest max_array [I] is the maximum number of dropped subsequences. Code of the key part of Java:

For (INT I = 1; I <length; I ++ ){

For (Int J = 0; j <I; j ++ ){

If (num_array [I] <= num_array [J] & max_array [I] <= max_array [J])

Max_array [I] ++;

}

Max_value = (max_array [I]> max_value )? Max_array [I]: max_value;

}

Max_value is the final result.

Code with detailed comments can be obtained at http://download.csdn.net/user/china8848/

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.