Longest ascending subsequence-classic DP

Source: Internet
Author: User

Longest ascending subsequence Time Limit: 3000 Ms memory limit: 65536 k any questions? Click Here ^_^ This topic describes a number sequence Bi, when B 1 <B 2 <... <B S We call this sequence ascending. For a given sequence ( 1 , 2 ,..., N ), We can get some ascending subsequences ( I1 , I2 ,..., Ik ), Here 1 <= I1 <I 2 <... <I K <= N. For example, for a sequence (1, 7, 3, 5, 9, 4, 8), some of its ascending subsequences, such as (1, 7), (3, 4, 8. The longest length of these subsequences is 4, for example, subsequences (1, 3, 5, 8 ).

Your task is to find the length of the longest ascending subsequence for the given sequence. The first line of the input is the sequence length N (1 <= n <= 1000 ). The second row contains N integers in the sequence. The values of these integers range from 0 to 10000. The length of the output longest ascending subsequence. Sample Input
 
71 7 3 5 9 4 8
Sample output
 
4
The source is northeastern Europe 2002. Presumably this is a very classic DP question. I have been studying DP for several days. I have done a few questions with ignorance. Most of them are done in the report on solving problems, I think the only way to improve DP is to do more exercises-I will post it for each DP in the future. I 'd like to summarize the ideas for solving DP problems first, get a DP question first (at present, this scum cannot determine whether to use DP without being certain (will it be said again ..)) First, we need to break down a problem Sub-questions So what are the sub-problems of this problem? The longest ascending subsequence of a series whose length is N is required .. n) the longest ascending subsequence of the ending series is a subproblem. Status For each k value, it corresponds to a number (with a (k) as the end point, the longest ascending subsequence length). Assume that the value is DP [K ]. DP [k] = max {DP [I], 1 = <I <k, and a (I) <A (K) and k! = 1} + 1 (state transition equation)

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.