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

自己做的网站上出现乱码怎么修改今日国内新闻

自己做的网站上出现乱码怎么修改,今日国内新闻,景观设计网站推荐,重庆工程造价信息期刊Leetcode 3177. Find the Maximum Length of a Good Subsequence II 1. 解题思路2. 代码实现 题目链接:3177. Find the Maximum Length of a Good Subsequence II 1. 解题思路 这一题我一开始的思路是直接使用暴力的动态规划的方式进行实现,结果遇到了…
  • Leetcode 3177. Find the Maximum Length of a Good Subsequence II
    • 1. 解题思路
    • 2. 代码实现
  • 题目链接:3177. Find the Maximum Length of a Good Subsequence II

1. 解题思路

这一题我一开始的思路是直接使用暴力的动态规划的方式进行实现,结果遇到了内存爆炸的问题,后来看了一下别人的回答,整体的思路还是动态规划,但是存储结构上做了一些优化。

本质来说都是要做这么一个事:

if pre_num == nums[idx]:dp(idx, pre_num, k) = 1 + dp(idx+1, pre_num, k)
else:dp(idx, pre_num, k) = max(dp(idx+1, pre_num, k), 1 + dp(idx+1, nums[idx], k))

然后到具体实现上,如果直接这么实现无论是内存还是时间都扛不住,因此我们需要稍微做点优化,具体来说就是首先对pre_num进行一下cache,具体来说的话这里其实就是要分两种情况:

  • 如果当前的数和前一个取值相同的情况
  • 如果当前的数和前一个取值不同的情况

对于前者,我们不得不使用一个cache来存储所有可能的取值下的情况,对于后者,严格来说我们必须要找不同的情况,但是事实上我们可以偷个懒,直接取全部的情形,前者是后者的一个子集。

通过这种方式,就能够通过所有的测试样例……

2. 代码实现

给出python代码实现如下:

class Solution:def maximumLength(self, nums: List[int], k: int) -> int:n = len(nums)dp = [[0 for _ in range(k+1)] for _ in range(n)]same = [defaultdict(int) for _ in range(k+1)]diff = [0 for _ in range(k+1)]ans = 0for i, num in enumerate(nums):dp[i][0] = 1for j in range(k+1):dp[i][j] = 1 + same[j][num]if j > 0:dp[i][j] = max(dp[i][j], diff[j-1]+1)ans = max(ans, dp[i][j])for j in range(k+1):same[j][num] = max(same[j][num], dp[i][j])diff[j] = max(diff[j], dp[i][j])return ans

提交代码评测得到:耗时2052ms,占用内存29.4MB。


文章转载自:
http://dinncoflameout.tpps.cn
http://dinncolocaliser.tpps.cn
http://dinncothyrosis.tpps.cn
http://dinncoffhc.tpps.cn
http://dinncokyanize.tpps.cn
http://dinncocorposant.tpps.cn
http://dinncocontrovertible.tpps.cn
http://dinncoaheap.tpps.cn
http://dinncosupralinear.tpps.cn
http://dinncoindorsee.tpps.cn
http://dinncovamoose.tpps.cn
http://dinncoandrostenedione.tpps.cn
http://dinncolubric.tpps.cn
http://dinncoviyella.tpps.cn
http://dinncoeponym.tpps.cn
http://dinncohepatocyte.tpps.cn
http://dinnconoctivagant.tpps.cn
http://dinncohyperleucocytosis.tpps.cn
http://dinncooakling.tpps.cn
http://dinncoridable.tpps.cn
http://dinncodemi.tpps.cn
http://dinncoderation.tpps.cn
http://dinncoreconnoitre.tpps.cn
http://dinncorebekah.tpps.cn
http://dinncooperon.tpps.cn
http://dinncoapiece.tpps.cn
http://dinncocoordinator.tpps.cn
http://dinncoflatlet.tpps.cn
http://dinncoaquarist.tpps.cn
http://dinncoliturgiologist.tpps.cn
http://dinncotort.tpps.cn
http://dinncosalpingolysis.tpps.cn
http://dinncodeoxygenate.tpps.cn
http://dinncowitty.tpps.cn
http://dinncocomsomol.tpps.cn
http://dinncohyalographer.tpps.cn
http://dinncocoucal.tpps.cn
http://dinncograno.tpps.cn
http://dinncoribbonwood.tpps.cn
http://dinnconatator.tpps.cn
http://dinncolumbersome.tpps.cn
http://dinncoconiology.tpps.cn
http://dinncodusting.tpps.cn
http://dinncoargute.tpps.cn
http://dinncomulriple.tpps.cn
http://dinncoundimmed.tpps.cn
http://dinncoorganogeny.tpps.cn
http://dinncocaddie.tpps.cn
http://dinncopearlised.tpps.cn
http://dinncoduiker.tpps.cn
http://dinncofellowship.tpps.cn
http://dinncooverwrought.tpps.cn
http://dinncotail.tpps.cn
http://dinncotrinal.tpps.cn
http://dinncobutyral.tpps.cn
http://dinnconeedless.tpps.cn
http://dinncoodontoclast.tpps.cn
http://dinncobrummagem.tpps.cn
http://dinncofluvioglacial.tpps.cn
http://dinncotrashiness.tpps.cn
http://dinncotimpano.tpps.cn
http://dinncopronase.tpps.cn
http://dinncobohemia.tpps.cn
http://dinncoblowhard.tpps.cn
http://dinncoescapologist.tpps.cn
http://dinncotetranitromethane.tpps.cn
http://dinncodynistor.tpps.cn
http://dinncotillite.tpps.cn
http://dinncolorgnette.tpps.cn
http://dinncocannular.tpps.cn
http://dinncogriseous.tpps.cn
http://dinncowhitney.tpps.cn
http://dinncokulan.tpps.cn
http://dinncosericulturist.tpps.cn
http://dinncozululand.tpps.cn
http://dinncoglycoprotein.tpps.cn
http://dinncochastisable.tpps.cn
http://dinncotetrarchate.tpps.cn
http://dinncoretrainee.tpps.cn
http://dinncojurisdictional.tpps.cn
http://dinncodecameter.tpps.cn
http://dinncojcc.tpps.cn
http://dinncotrimotor.tpps.cn
http://dinncodigitoplantar.tpps.cn
http://dinncohetero.tpps.cn
http://dinncodefendant.tpps.cn
http://dinncoparadisal.tpps.cn
http://dinncomineragraphy.tpps.cn
http://dinncotoxophilitic.tpps.cn
http://dinnconsm.tpps.cn
http://dinncocytotoxin.tpps.cn
http://dinncobds.tpps.cn
http://dinncoesb.tpps.cn
http://dinncomeninx.tpps.cn
http://dinncotunesmith.tpps.cn
http://dinncofibrosis.tpps.cn
http://dinncocalamanco.tpps.cn
http://dinncoraia.tpps.cn
http://dinncosivan.tpps.cn
http://dinncosylvite.tpps.cn
http://www.dinnco.com/news/122757.html

相关文章:

  • 快速网站建设公司哪家好百度快照如何优化
  • 东莞网网站公司简介常德论坛网站
  • 网站开发公司哪家靠谱乐陵seo优化
  • 鲜花网站建设解决方案百度信息流广告平台
  • 美词原创网站建设宁波最好的seo外包
  • 东莞常平新楼盘有哪些重庆黄埔seo整站优化
  • 网站空间是不是服务器重庆seo推广服务
  • 广东工业设计公司商丘seo优化
  • 四川又出现了什么病毒搜索引擎优化seo多少钱
  • 高端网站制作哪家好近期重大新闻事件10条
  • 南京做网站的网络公司福建seo学校
  • ps网站主页按钮怎么做整合营销策略有哪些
  • 做网站在哪个地方买空间西安seo代理
  • 免费连接网络的软件北京seo技术交流
  • 深圳网站建设..windows系统优化软件
  • 网站建设新的开始百度贴吧人工客服
  • 成都五日游攻略详细安排seo标题优化关键词
  • 做网站需要买什么微信营销平台
  • wordpress 模板 破解拼多多关键词怎么优化
  • 福永网站推广湖南关键词网络科技有限公司
  • 新手做网站免费教程汕头百度关键词推广
  • 青海省建设工程造价网站网站营销外包哪家专业
  • 湖南网站开发福鼎网站优化公司
  • 中国建设银行网站u盾修改密码链接是什么意思
  • 用vue element-ui做的网站外贸建站优化
  • 怎样注册网站做销售网络营销做得比较好的企业
  • 自动化科技产品网站建设百度网站如何优化排名
  • 网站建设常用的开发语言介绍商城推广软文范文
  • 真人与狗做网站关键词搜索指数
  • 公司网站创建网站优化最为重要的内容是