LCS(Needleman_Wunsch算法)算法 (python实现)

最长公共子序列(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
                
发布了26 篇原创文章 · 获赞 3 · 访问量 1395

猜你喜欢

转载自blog.csdn.net/qq_42937176/article/details/103548313
今日推荐