最长公共子序列(LCS)

思路:

代码:

def LCS(string1,string2):
    len1 = len(string1)
    len2 = len(string2)
    res = [[0 for i in range(len1+1)] for j in range(len2+1)]
    for i in range(1,len2+1):
        for j in range(1,len1+1):
            if string2[i-1] == string1[j-1]:
                res[i][j] = res[i-1][j-1]+1
            else:
                res[i][j] = max(res[i-1][j],res[i][j-1])
    return res,res[-1][-1]
print(LCS("helloworld","loop"))

最长公共子串

思路:

代码:

def LCstring(string1,string2):
    len1 = len(string1)
    len2 = len(string2)
    res = [[0 for i in range(len1+1)] for j in range(len2+1)]
    result = 0
    for i in range(1,len2+1):
        for j in range(1,len1+1):
            if string2[i-1] == string1[j-1]:
                res[i][j] = res[i-1][j-1]+1
                result = max(result,res[i][j])
    return result
print(LCstring("helloworld","loop"))

链接:https://blog.csdn.net/ggdhs/article/details/90713154

最新文章

  1. 制作bat脚本,抓取Android设备logcat
  2. OLAP在大数据时代的挑战
  3. 图解六大UML类图关系
  4. 不同版本vpb与osg对应关系
  5. 035. asp.netWeb用户控件之四通过用户控件实现投票和结果分析
  6. 无线局域网络 WIFI/WAPI/WLAN区别浅析
  7. [原创]Android Handler使用Message的一个注意事项
  8. 20145211 《Java程序设计》第6周学习总结——三笑徒然当一痴
  9. SVG 是什么?
  10. nginx打开目录游览功能
  11. 为rm命令增加回收站功能
  12. bzoj3157 3516
  13. Oracle---->基本DDL
  14. chattr命令
  15. list的三种遍历方法
  16. CheckBox in ListView
  17. 记录 制作校园网登陆脚本 python编写 附源码
  18. POJ - 3984 迷宫问题 bfs解法
  19. vue2.4+vue-cli+webpack history模式打包后 刷新404
  20. Java 中的E,K,V,T,U,S

热门文章

  1. git 打tag(版本)、推送代码
  2. 图解 perspective && perspective-origin && transform3d && transform-origin
  3. [Google] Help employee find the nearest gbike
  4. Swoole练习 UDP
  5. unix 命令
  6. qt linux下自动检测U盘热插拔
  7. 《ucore lab6》实验报告
  8. twemproxy配置
  9. LeetCode 637. 二叉树的层平均值(Average of Levels in Binary Tree)
  10. [转帖]LINUX下使用rinetd端口转发