每日一题-——最长公共子序列(LCS)与最长公共子串
2024-08-26 11:08:42
最长公共子序列(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
最新文章
- 制作bat脚本,抓取Android设备logcat
- OLAP在大数据时代的挑战
- 图解六大UML类图关系
- 不同版本vpb与osg对应关系
- 035. asp.netWeb用户控件之四通过用户控件实现投票和结果分析
- 无线局域网络 WIFI/WAPI/WLAN区别浅析
- [原创]Android Handler使用Message的一个注意事项
- 20145211 《Java程序设计》第6周学习总结——三笑徒然当一痴
- SVG 是什么?
- nginx打开目录游览功能
- 为rm命令增加回收站功能
- bzoj3157 3516
- Oracle---->;基本DDL
- chattr命令
- list的三种遍历方法
- CheckBox in ListView
- 记录 制作校园网登陆脚本 python编写 附源码
- POJ - 3984 迷宫问题 bfs解法
- vue2.4+vue-cli+webpack history模式打包后 刷新404
- Java 中的E,K,V,T,U,S
热门文章
- git 打tag(版本)、推送代码
- 图解 perspective &;&; perspective-origin &;&; transform3d &;&; transform-origin
- [Google] Help employee find the nearest gbike
- Swoole练习 UDP
- unix 命令
- qt linux下自动检测U盘热插拔
- 《ucore lab6》实验报告
- twemproxy配置
- LeetCode 637. 二叉树的层平均值(Average of Levels in Binary Tree)
- [转帖]LINUX下使用rinetd端口转发