A few simple steps teach you to solve LIS, LCS, LICS problems

LIS, LCS, and LICS are all basic models in dp,

Today, when reviewing the longest common ascending subsequence problem, I briefly summarized these three types of problems

LCS (Longest Common Subsequence)

The description is given two sequence, find the length of the longest common subsequence in the two sequence.

State definition:

f (i, j) is the length of the longest common subsequence composed of the first i numbers of sequence a and the first j numbers of sequence b

Transfer equation:

f(i, j) = f(i - 1,j - 1) + 1 (i, j > 0,a[i] == b[j])

f(i, j) = max(f (i - 1, j),f(i, j - 1) ) (i, j > 0, a[i] != b[j] );

LIS (Longest Ascending Subsequence)

The description is given a sequence, find the length of the longest ascending subsequence in this sequence

State definition:

f(j) is the length of the longest ascending subsequence ending with the given sequence a[j]

Transfer equation:

f[j] = max f[j] + 1;(j < i,a[j] < a[i] )

LICS (longest common ascending subsequence)

The description is given two sequences, find the length of the longest common ascending subsequence in the two sequences

State definition:

f(i, j) is the LICS length of the first i elements of sequence a and the first j elements of sequence b ending with b[j]

t is the end element position of the longest LICS

Transfer equation:

f[i][j] = f[i - 1][j] (a[i] != b[j])

f[i][j] = max(f[i - 1][j],f[i - 1][t] + 1) (a[i] == b[j])

Guess you like

Origin blog.csdn.net/m0_66252872/article/details/125273045