Dynamic programming (the longest increasing subsequence)

The longest increasing subsequence

  Given a sequence of {S1, S2, ..., Sn }, a number taken to form a new sequence number {Si1, Si2, ..., Sim }, where i1, i2 ... im keeps increasing, i.e. in the new sequence each number remains the original number of columns in the order, said the new sequence is a sequence of the original sequence .

  If the subsequence, when lower ix> when iy, Six> Siy, known as a sub-sequence of the original sequence of increasing subsequence .

  Define a memory array dp longest increasing subsequence length, dp [n] denotes the end of the longest increasing sequence length sequence of Sn. For an increasing subsequence {Si1, Si2, ..., Sim}, if im <n and Sim <Sn, In this case {Si1, Si2, ..., Sim, Sn} is an increasing sequence, increasing subsequence an increase in length. Incrementing sequence satisfying the above condition, the length of the longest increasing subsequence that is to find, together constitute a Sn containing Sn as the end of the longest increasing the length of the longest sequence in the sequence is incremented. Therefore dp [n] = max {dp [i] +1 | Si <Sn && i <n}.

  Since the seeking may not be found when dp [n] is incremented sequence satisfies a condition, at this time constitutes the {Sn} is incremented sequence, a need to make modifications to the foregoing equation solving, so dp [n] is a minimum, i.e. :

  dp[n]=max{1,dp[i]+1|Si<Sn&&i<n}

  For a sequence of length N, is not necessarily the longest increasing subsequence ending of Sn, thus dp [N] is not the longest increasing sequence length of the sequence, the array need to be traversed to find dp desired result is maximum .

Guess you like

Origin www.cnblogs.com/yjxyy/p/11118981.html