LCS
作者:互联网
dp[ i ][ j ]表示字符串S1前 i 个字符与字符串S2前 j 个字符的LCS长度,若对应字符相等,则长度加一,否则继承长度。
for ( int i = 1 ; i <= len1 ; i++ ) { for ( int j = 1 ; j <= len2 ; j++ ) { if ( S1 [ i ] == S2 [ j ] ) dp [ i ][ j ] = max ( dp [ i ][ j ] , dp [ i - 1 ][ j - 1 ] + 1 ) ; else dp [ i ][ j ] = max ( dp [ i - 1 ][ j ] , dp [ i ][ j - 1 ] ) ; } }
标签:加一,LCS,S2,字符串,长度,个字符 来源: https://www.cnblogs.com/xqk0225/p/16078410.html