标签:二维数组 splay 区别 play bst 符号 comm 说明 相关
英文名称:
主要区别:子串必须要连续,子序列不需要
def longest_common_subsequence(X: str, Y: str):
index_x = len(X)+1 # columns
index_y = len(Y)+1 # rows
c = [[‘‘]*index_y for _ in range(index_x)]
for i in range(index_x):
for j in range(index_y):
if i == 0 or j == 0:
c[i][j] = ‘‘
continue
if X[i-1] == Y[j-1]:
c[i][j] = c[i-1][j-1] + X[i-1]
else:
if len(c[i-1][j]) > len(c[i][j-1]):
c[i][j] = c[i-1][j]
else:
c[i][j] = c[i][j-1]
return len(c[index_x-1][index_y-1]), c[index_x-1][index_y-1]
方法差不多,有人看再更
动态规划——最长公共子序列与最长公共子串 (含Python实现代码)
标签:二维数组 splay 区别 play bst 符号 comm 说明 相关
原文地址:https://www.cnblogs.com/Homunculus/p/13266706.html