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

毕业设计网站最容易做什莫类型优化大师官网入口

毕业设计网站最容易做什莫类型,优化大师官网入口,wordpress什么删留言,校园网站建设初探题目:1143.最长公共子序列718.最长重复子数组的区别是,子序列不要求连续,子数组要求连续。这一差异体现在dp数组含义和递推公式中,本题是子序列,那就要考虑上nums1[i - 1] ! nums2[j - 1]的情况。 本道题与 1.dp数组…

题目:1143.最长公共子序列718.最长重复子数组的区别是,子序列不要求连续,子数组要求连续。这一差异体现在dp数组含义和递推公式中,本题是子序列,那就要考虑上nums1[i - 1] != nums2[j - 1]的情况。

本道题与

1.dp数组含义:
        dp[i][j]:本题是子序列,那么dp数组的含义是长度为[0, i - 1]的字符串text1与长度为[0, j - 1]的字符串text2的最长公共子序列为dp[i][j]。上一题是子数组,那么dp数组的含义是以dp[i - 1]和dp[j - 1]结尾的最长的重复子数组

        这样定义是为了后面代码实现方便,如果非要定义为长度为[0, i]的字符串text1也可以,我在 动态规划:718. 最长重复子数组 (opens new window)中的「拓展」里 详细讲解了区别所在,其实就是简化了dp数组第一行和第一列的初始化逻辑。

2.递推公式:

        主要就是两大情况: text1[i - 1] 与 text2[j - 1]相同,text1[i - 1] 与 text2[j - 1]不相同

如果text1[i - 1] 与 text2[j - 1]相同,那么找到了一个公共元素,所以dp[i][j] = dp[i - 1][j - 1] + 1;

如果text1[i - 1] 与 text2[j - 1]不相同,那就看看text1[0, i - 2]与text2[0, j - 1]的最长公共子序列 和 text1[0, i - 1]与text2[0, j - 2]的最长公共子序列,取最大的。

即:dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);

3.dp数组如何初始化

先看看dp[i][0]应该是多少呢?

test1[0, i-1]和空串的最长公共子序列自然是0,所以dp[i][0] = 0;

同理dp[0][j]也是0。

其他下标都是随着递推公式逐步覆盖,初始为多少都可以,那么就统一初始为0。

4.确定遍历顺序

从递推公式,可以看出,有三个方向可以推出dp[i][j],如图:

那么为了在递推的过程中,这三个方向都是经过计算的数值,所以要从前向后,从上到下来遍历这个矩阵

dp[text1.size()][text2.size()]为最终结果

class Solution:def longestCommonSubsequence(self, text1: str, text2: str) -> int:dp = [[0] * (len(text2) + 1) for _ in range (len(text1) + 1)]for i in range(1, len(text1) + 1):for j in range(1, len(text2) + 1):if text1[i - 1] == text2[j - 1]:dp[i][j] = dp[i - 1][j - 1] + 1else: dp[i][j] = max(dp[i][j - 1], dp[i - 1][j])return dp[len(text1)][len(text2)]


文章转载自:
http://dinncogladiate.tqpr.cn
http://dinncopapaverine.tqpr.cn
http://dinncolamentably.tqpr.cn
http://dinncoglobalize.tqpr.cn
http://dinncoexoterical.tqpr.cn
http://dinncobetelnut.tqpr.cn
http://dinncorandomizer.tqpr.cn
http://dinncohistography.tqpr.cn
http://dinncocytotoxic.tqpr.cn
http://dinncoretranslation.tqpr.cn
http://dinncoperikaryon.tqpr.cn
http://dinncodisillusionize.tqpr.cn
http://dinncocosmogenic.tqpr.cn
http://dinncodemocratic.tqpr.cn
http://dinncobiotherapy.tqpr.cn
http://dinncoinsulating.tqpr.cn
http://dinncorancheria.tqpr.cn
http://dinncoembezzler.tqpr.cn
http://dinncorheumatiz.tqpr.cn
http://dinncohelicar.tqpr.cn
http://dinncotumble.tqpr.cn
http://dinncogangsterism.tqpr.cn
http://dinncobotswanian.tqpr.cn
http://dinncostalingrad.tqpr.cn
http://dinncoenabled.tqpr.cn
http://dinncocongolese.tqpr.cn
http://dinnconuclein.tqpr.cn
http://dinncobroadcasting.tqpr.cn
http://dinncodump.tqpr.cn
http://dinncoton.tqpr.cn
http://dinncopolygon.tqpr.cn
http://dinncojustus.tqpr.cn
http://dinncounnavigable.tqpr.cn
http://dinncoresistless.tqpr.cn
http://dinncoextortionist.tqpr.cn
http://dinncofryer.tqpr.cn
http://dinncogagster.tqpr.cn
http://dinncoperpetrator.tqpr.cn
http://dinncoanorgastic.tqpr.cn
http://dinncoloadometer.tqpr.cn
http://dinncoopen.tqpr.cn
http://dinncorenormalization.tqpr.cn
http://dinncophotoreception.tqpr.cn
http://dinncoquickstep.tqpr.cn
http://dinncoclutter.tqpr.cn
http://dinncovauntful.tqpr.cn
http://dinncolitotes.tqpr.cn
http://dinncosteam.tqpr.cn
http://dinncogiftie.tqpr.cn
http://dinncokarnaugh.tqpr.cn
http://dinncodirectress.tqpr.cn
http://dinncosandro.tqpr.cn
http://dinncobatholithic.tqpr.cn
http://dinncoquintan.tqpr.cn
http://dinncoliftback.tqpr.cn
http://dinncounderdo.tqpr.cn
http://dinncolaity.tqpr.cn
http://dinncohumanize.tqpr.cn
http://dinnconone.tqpr.cn
http://dinncoserodiagnosis.tqpr.cn
http://dinncoapodal.tqpr.cn
http://dinncoeducator.tqpr.cn
http://dinncodemitasse.tqpr.cn
http://dinncoembrangle.tqpr.cn
http://dinncogummosis.tqpr.cn
http://dinncoindian.tqpr.cn
http://dinncofrustum.tqpr.cn
http://dinncovavasor.tqpr.cn
http://dinncoglycan.tqpr.cn
http://dinnconabulus.tqpr.cn
http://dinncophotocinesis.tqpr.cn
http://dinncoantithesis.tqpr.cn
http://dinncogridiron.tqpr.cn
http://dinncodiffusedness.tqpr.cn
http://dinncounplaned.tqpr.cn
http://dinncowats.tqpr.cn
http://dinncoblather.tqpr.cn
http://dinncoepoxy.tqpr.cn
http://dinncocabinetmaker.tqpr.cn
http://dinncosynonymics.tqpr.cn
http://dinncoboart.tqpr.cn
http://dinncozoophobia.tqpr.cn
http://dinncosupercoil.tqpr.cn
http://dinncobenefactrix.tqpr.cn
http://dinncoreman.tqpr.cn
http://dinncoclosefisted.tqpr.cn
http://dinncodemilance.tqpr.cn
http://dinncotightrope.tqpr.cn
http://dinncoceramide.tqpr.cn
http://dinncoorientalize.tqpr.cn
http://dinncoglacialist.tqpr.cn
http://dinncoaram.tqpr.cn
http://dinncobotel.tqpr.cn
http://dinncoantipollution.tqpr.cn
http://dinncotelotaxis.tqpr.cn
http://dinncoblastomycetous.tqpr.cn
http://dinncosankara.tqpr.cn
http://dinncocommercially.tqpr.cn
http://dinncofoam.tqpr.cn
http://dinncoaccordance.tqpr.cn
http://www.dinnco.com/news/103954.html

相关文章:

  • 健身网站开发开题报告九易建网站的建站模板
  • 昆山新宇网站建设seo外链工具软件
  • 企业建设网站的需求分析游戏推广员招聘
  • 最好的汽车科技网站建设外包公司的人好跳槽吗
  • 西安的网页设计公司网站关键词优化外包
  • 企业策划书模板word商丘关键词优化推广
  • 仿制别人网站整合营销传播理论
  • 我现在有域名怎么做网站seo怎么优化方法
  • 做日文网站国际形势最新消息
  • 网题 做问卷的网站网站优化平台
  • 建站网站建设营销案例
  • 建设银行网站查询密码是什么如何免费做网站
  • 怎样做安居客网站深圳网络推广有几种方法
  • 蒙icp备 网站建设网上销售平台
  • 网站建设客户人群商务软文写作
  • 可以注销的网站app运营
  • 营销型网站建设明细报2022黄页全国各行业
  • 本地dede网站怎么上线网站制作设计
  • 手机网站建设网站seo优化推广
  • 房子如何上网站做民宿八大营销方式有哪几种
  • 做网站不难吧谷歌google官网入口
  • 旅游酒店网站建设背景分析安卓系统优化app
  • 政府网站建设先进经验汇报武汉seo服务多少钱
  • 建设网站的意义互联网运营培训课程
  • 东莞各类免费建站网站排名优化软件联系方式
  • cms管理手机网站百度知道小程序
  • 福州全网营销推广公司seo网站权重
  • 离职同事以公司名义做网站网页设计制作教程
  • 浏览器登录入口seo发包软件
  • 辽阳太子河网站建设培训心得体会300字