最长公共子序列(longest common subsequence,LCS)
# -*- coding: utf-8 -*-
"""
Created on Tue Nov 26 19:55:48 2019
@author: HTING
"""
import numpy as np
def LCS(str1,str2):
s = 0
l = np.zeros([len(str2)])
for i in range(0,len(str1)):
for j in range(len(str2)-1,-1,-1):
if str1[i] == str2[j]:
if i == 0 or j == 0:
l[j] == 1
else:
l[j] = l[j-1] + 1
else:
l[j] = 0
if l[j] > s: s = l[j]
return s+1