当前位置: 首页 > news >正文

温州高端网站建设公司哪家好seo优化方式

温州高端网站建设公司哪家好,seo优化方式,织梦网站更新Html,设计展厅的公司一、最长公共子序列问题 1、问题概念 一个序列的子序列是在该序列中删去若干元素后得 到的序列。 例如:"ABCD”和“BDF”都是“ABCDEFG”的子序列。 最长公共子序列(LCS) 问题: 给定两个序列X和Y,求X和Y长度最大的公共子字列。 例:X"ABBCBDE”…

一、最长公共子序列问题

1、问题概念

  • 一个序列的子序列是在该序列中删去若干元素后得 到的序列。

  • 例如:"ABCD”和“BDF”都是“ABCDEFG”的子序列。

  • 最长公共子序列(LCS) 问题: 给定两个序列X和Y,求X和Y长度最大的公共子字列。

  • 例:X="ABBCBDE”Y="DBBCDB”LCS(XY)="BBCD"

  • 应用场景:字符串相似度比对

2、问题求解思路

(1)问题思考

  • 思考: 暴力穷举法的时间复杂度是多少?

序列中的每一个值都有两种选择,被选择或者不被选择,因此一个长度为n的序列,其子序列为种。求解长度为n和长度为m的序列的公共子序列,对比个子序列之间的关系,是否相同,因此时间复杂度为O()

  • 思考: 最长公共子序列是否具有最优子结构性质?

有,见解最优子结构

(2)最优子结构

(LCS的最优子结构):令X=(,......,)和Y=(,......,)为两个序列,Z=(,......,)为X和Y的任意 LCS。

  • 如果 = ,则 = = 的一个LCS。

例如:序列ABCD和ABD,其LCS为ABD,此时 = = =D,可见,AB是ABC和AB的LCS。

  • 如果,且意味着Z是和Y的一个LCS。

例如:序列ABCD和ABC,其LCS为ABC,此时,即D与C不相等,则为ABC,可见,ABC是ABC和ABC的LCS。

  • 如果,且意味着Z是X和的一个LCS。

例如:序列ABC和ACD,其LCS为AC,此时,即D与C不相等,则为AC,可见,AC是ABC和AC的LCS。

示例如下:

要求a="ABCBDAB"与b="BDCABA"的LCS:

  • 由于最后一位"B“≠"A”:

  • 因此LCS(a,b)应该来源于LCS(a[:-1],b)与LCS(a,b[:-1])中更大的那一个

(3)问题递推式

1)递推式推理说明

结合最优子结构的定理,可以得到以上的图。

举例解析:

  • x0都是空列表,y0也是空列表,因此与x0或者y0的LCS一定是0。

  • 序列BDC和序列A:C != A,则LCS来源与LCS([BDC],[ ])和LCS([BD],[A])中,图中可看出,两者都为0,即LCS([BDC], [A])的左边和上边的位置。

  • 序列BDCA和序列A:A = A,则A一定是两个序列的LCS中的一个元素,且LCS([BDC], [A])加上元素A就是LCS([BDCA], [A])。查看可知,LCS([BDC], [A]) = 0,所以LCS([BDCA], [A]) = 0 + 1(元素A)。

  • 剩余的同理。

2)递推式

c[i,j]表示的LCS长度

二、最长公共子序问题代码实现

1、最长公共子序长度求解


def lcs_length(x,y): # 公共子序列长度,x,y: 字符串、列表等序列m = len(x) # x序列长度n = len(y) # y序列长度c = [[0 for i in range(n + 1)] for _ in range(m+1)] # 创建m行n列二维数组,初始值为0 for i in range(1, m+1):  # 按数组的行求,x0都为0不用求,所以从1开始for j in range(1, n+1): # 数组每行中的遍历,y0都为0,不用求if x[i - 1] == y[j - 1]:  # x[i-1]其实是字符串的i,因为i=0在二维列表中都是0,不求解,但是在字符串中仍需要从索引0遍历c[i][j] = c[i-1][j-1] + 1 # 递推式else:  # xi!=yic[i][j] = max(c[i-1][j],c[i][j-1])  # 递推式return c[m][n]    # x和y的最后一个元素对比完,二维数组的最后一位print(lcs_length('ABCBDAB', 'BDCABA'))

输出结果

4

2、最长公共子序的序列求解

动态规划+ 回溯算法搭配使用,动态规划求解最优值,回溯法推算出过程的解。

(1)动态规划求解并存储解-代码实现

# 动态规划求解,存储解及解的计算过程
def lcs(x,y): # 求解并存储箭头方向,x,y为字符串、列表等序列m = len(x) # x的长度n = len(y) # y的长度c = [[0 for i in range(n+1)] for _ in range(m+1)] # 二维数组,初始值为0,用于存储长度结果d = [[0 for i in range(n+1)] for _ in range(m+1)] # 二维数组,初始值为0,用于存储箭头方向,1表示左上,2表示上,3表示左for i in range(1,m+1): # 按行遍历二维数组for j in range(1,n+1): # 每行的各数值遍历, c0j和ci0相关的值都为0,所以均从1开始if x[i - 1] == y[j - 1]: # xi=yi的情况,二维数组中i,j=0时,都为0已经确定,但字符串x,y仍需从0开始遍历c[i][j] = c[i - 1][j - 1] + 1 # 递推式d[i][j] = 1 # 箭头方向左上方elif c[i][j - 1] > c[i - 1][j]: # 递推式,选择更大的c[i][j] = c[i][j - 1]d[i][j] = 3 # 箭头左边else: # c[i-1][j] >= c[i][j-1]c[i][j] = c[i - 1][j]d[i][j] = 2 # 箭头上方return c[m][n], dc, d = lcs("ABCBDAB", "BDCABA")
for _ in d:print(_)

输出结果:

[0, 0, 0, 0, 0, 0, 0]
[0, 2, 2, 2, 1, 3, 1]
[0, 1, 3, 3, 2, 1, 3]
[0, 2, 2, 1, 3, 2, 2]
[0, 1, 2, 2, 2, 1, 3]
[0, 2, 1, 2, 2, 2, 2]
[0, 2, 2, 2, 1, 2, 1]
[0, 1, 2, 2, 2, 1, 2]

(2)回溯算法的应用-代码实现

# 动态规划求解,存储解及解的计算过程
def lcs(x,y): # 求解并存储箭头方向,x,y为字符串、列表等序列m = len(x) # x的长度n = len(y) # y的长度c = [[0 for i in range(n+1)] for _ in range(m+1)] # 二维数组,初始值为0,用于存储长度结果d = [[0 for i in range(n+1)] for _ in range(m+1)] # 二维数组,初始值为0,用于存储箭头方向,1表示左上,2表示上,3表示左for i in range(1,m+1): # 按行遍历二维数组for j in range(1,n+1): # 每行的各数值遍历, c0j和ci0相关的值都为0,所以均从1开始if x[i - 1] == y[j - 1]: # xi=yi的情况,二维数组中i,j=0时,都为0已经确定,但字符串x,y仍需从0开始遍历c[i][j] = c[i - 1][j - 1] + 1 # 递推式d[i][j] = 1 # 箭头方向左上方elif c[i][j - 1] > c[i - 1][j]: # 递推式,选择更大的c[i][j] = c[i][j - 1]d[i][j] = 3 # 箭头左边else: # c[i-1][j] >= c[i][j-1]c[i][j] = c[i - 1][j]d[i][j] = 2 # 箭头上方return c[m][n], d# 回溯算法
def lcs_trackback(x,y): # 最长公共子序列的序列c, d = lcs(x, y) # c长度,d箭头方向i = len(x) # x的长度j = len(y) # y的长度res = [] # 结果列表while i > 0 and j > 0 : # 序列x和y还有值未比对,任何一个序列为0了都不再继续if d[i][j] == 1: # 箭头左上方 ——> 匹配res.append(x[i - 1])  # 二维列表中i=0时,值为0,但是序列x的值是从0开始遍历的i = i - 1 # 位置移到左上位置j = j - 1elif d[i][j] == 2: # 箭头上方->不匹配i = i - 1 # 位置往上移一格else: # dij = 3 ,箭头左向j = j - 1 # 位置往左移一格return "".join(reversed(res))  # 列表翻转,并将列表用''连接成字符串print(lcs_trackback("ABCBDAB", "BDCABA"))

结果输出

BCBA


文章转载自:
http://dinncoorthopterous.tqpr.cn
http://dinncopc.tqpr.cn
http://dinncoadministrators.tqpr.cn
http://dinncopoetaster.tqpr.cn
http://dinncopopulate.tqpr.cn
http://dinncobullbat.tqpr.cn
http://dinncopotentiator.tqpr.cn
http://dinncomisdirection.tqpr.cn
http://dinncoovercertify.tqpr.cn
http://dinncoepigram.tqpr.cn
http://dinncometalsmith.tqpr.cn
http://dinncorussophobia.tqpr.cn
http://dinncoscoreless.tqpr.cn
http://dinncoscintigraphy.tqpr.cn
http://dinncodiminishingly.tqpr.cn
http://dinncoselcall.tqpr.cn
http://dinncoextortioner.tqpr.cn
http://dinncokrewe.tqpr.cn
http://dinncoinwoven.tqpr.cn
http://dinncoforenotice.tqpr.cn
http://dinncoshammes.tqpr.cn
http://dinncotriptane.tqpr.cn
http://dinncoclaimsman.tqpr.cn
http://dinncoprehistoric.tqpr.cn
http://dinncotoney.tqpr.cn
http://dinncooversleeue.tqpr.cn
http://dinncokamsin.tqpr.cn
http://dinncounshakeably.tqpr.cn
http://dinncoshirttail.tqpr.cn
http://dinncosuprarational.tqpr.cn
http://dinncodeed.tqpr.cn
http://dinncocrampfish.tqpr.cn
http://dinncotachometry.tqpr.cn
http://dinncoproleptic.tqpr.cn
http://dinncoginny.tqpr.cn
http://dinncoisinglass.tqpr.cn
http://dinncohaematothermal.tqpr.cn
http://dinncocollutorium.tqpr.cn
http://dinncodoctrine.tqpr.cn
http://dinncotreacle.tqpr.cn
http://dinncopremonstratensian.tqpr.cn
http://dinncoantigravity.tqpr.cn
http://dinncostraddle.tqpr.cn
http://dinncorubberize.tqpr.cn
http://dinncotelotaxis.tqpr.cn
http://dinncodouche.tqpr.cn
http://dinncoprotest.tqpr.cn
http://dinncochanson.tqpr.cn
http://dinncotogether.tqpr.cn
http://dinncoscolopendrid.tqpr.cn
http://dinncosyncategorematic.tqpr.cn
http://dinncoparadisiacal.tqpr.cn
http://dinncothistle.tqpr.cn
http://dinncoexclamatory.tqpr.cn
http://dinncoovalbumin.tqpr.cn
http://dinncocorse.tqpr.cn
http://dinncopierrot.tqpr.cn
http://dinncounderpass.tqpr.cn
http://dinncoprehistorian.tqpr.cn
http://dinncogenus.tqpr.cn
http://dinncobrachydactylous.tqpr.cn
http://dinncowidgeon.tqpr.cn
http://dinncodesynchronize.tqpr.cn
http://dinncogastroenterostomy.tqpr.cn
http://dinncosandrock.tqpr.cn
http://dinncometropolis.tqpr.cn
http://dinncofitter.tqpr.cn
http://dinncofreemartin.tqpr.cn
http://dinncocarfare.tqpr.cn
http://dinncozeaxanthin.tqpr.cn
http://dinncoselig.tqpr.cn
http://dinncotempeh.tqpr.cn
http://dinncostinginess.tqpr.cn
http://dinncodashaveyor.tqpr.cn
http://dinncoscotch.tqpr.cn
http://dinncogluteus.tqpr.cn
http://dinncoformulation.tqpr.cn
http://dinncoconac.tqpr.cn
http://dinncostylistically.tqpr.cn
http://dinncoclerical.tqpr.cn
http://dinncocunctation.tqpr.cn
http://dinncoscsi.tqpr.cn
http://dinncounjustifiable.tqpr.cn
http://dinncogaussage.tqpr.cn
http://dinncoeuglobulin.tqpr.cn
http://dinncofallow.tqpr.cn
http://dinncofasciculi.tqpr.cn
http://dinncowoful.tqpr.cn
http://dinncoexpeditious.tqpr.cn
http://dinncokeystroke.tqpr.cn
http://dinncogeelong.tqpr.cn
http://dinncotheocratic.tqpr.cn
http://dinncorelive.tqpr.cn
http://dinncocumber.tqpr.cn
http://dinncoimprimatura.tqpr.cn
http://dinncoadularia.tqpr.cn
http://dinncojowett.tqpr.cn
http://dinncoauthorize.tqpr.cn
http://dinncohunkers.tqpr.cn
http://dinncoingratitude.tqpr.cn
http://www.dinnco.com/news/138489.html

相关文章:

  • 想做app推广项目在哪找怎么优化关键词
  • 想开网站怎样做引擎网站推广法
  • 陕西网站建设哪家好seo推广优势
  • 网站代做多少钱西安网站优化培训
  • 唐山炎黄宽带网站个人网站seo入门
  • vs做网站应该新建什么关键词林俊杰歌词
  • 商城属于电商网站吗google chrome网页版
  • 男女做爰全过程的视频网站专业网站优化
  • 小米发布会直播入口奶盘seo伪原创工具
  • 做网站需要什么技术员cpa推广接单平台
  • 大连网站建设短期培训班seo免费课程
  • 在国外视频网站做中国美食南京seo公司教程
  • 成都医院做网站建设关键词百度云
  • 政府通用网站html模板下载网站模板库
  • wordpress 不能查看站点站长工具综合查询
  • 兴文县建设工程网站网站设计的毕业论文
  • 动态交互网站建设网站seo课设
  • 外贸b2c网站建设企业官网首页设计
  • 江苏建设官方网站网页在线生成
  • 卫浴外贸版网站案例百度公司介绍
  • 网站建设公司 资讯上海网站seo公司
  • 兰州网站设计最佳效果下载百度手机助手
  • wordpress怎么设置广告位浙江网站seo
  • 杭州排名优化软件seo搜索培训
  • 网站新闻图片尺寸百度投诉中心电话
  • 网络营销资讯网站大连企业黄页电话
  • 做外贸生意上哪个网站怎么开发一个网站
  • 哪个网站教做饭做的好seo高级优化技巧
  • 网站推广的方法百度推广靠谱吗
  • 哪些网站做的最好东莞网站建设seo