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

网站做授权登录界面百度在线问答

网站做授权登录界面,百度在线问答,视频网站怎么做压力测试,企业网站建设模板多少钱目录 100296. 两个字符串的排列差 原题链接 思路分析 AC代码 100274. 从魔法师身上吸取的最大能量 原题链接 思路分析 AC代码 100281. 矩阵中的最大得分 原题链接 思路分析 AC代码 100312. 找出分数最低的排列 原题链接 思路分析 AC代码 100296. 两个字符串的排…

目录

100296. 两个字符串的排列差

原题链接

思路分析

AC代码

100274. 从魔法师身上吸取的最大能量

原题链接

思路分析

AC代码

100281. 矩阵中的最大得分

原题链接

思路分析

AC代码

100312. 找出分数最低的排列

原题链接

思路分析

AC代码


100296. 两个字符串的排列差

原题链接

两个字符串的排列差 - 力扣 (LeetCode) 竞赛

思路分析

签到题,两次遍历搞定

AC代码

class Solution:def findPermutationDifference(self, s: str, t: str) -> int:mp = dict()res = 0for i, x in enumerate(s):mp[x] = ifor i, x in enumerate(t):res += abs(i - mp[x])return res

100274. 从魔法师身上吸取的最大能量

原题链接

从魔法师身上吸取的最大能量 - 力扣 (LeetCode) 竞赛

思路分析

记忆化搜索

dfs(0)代表从0出发的最大能量,记忆化剪枝保证每个结点只走一次

时间复杂度O(n)

AC代码

class Solution:def maximumEnergy(self, energy: List[int], k: int) -> int:n = len(energy)@cache def dfs(x: int) -> int:if x >= n:return 0return energy[x] + dfs(x + k)return max(dfs(i) for i in range(n))

100281. 矩阵中的最大得分

原题链接

矩阵中的最大得分 - 力扣 (LeetCode) 竞赛

思路分析

典中典网格上递推,为了拼手速还是用的记忆化搜索

不过注意起点特判,可以在递归函数里面多加个bool参数

时间复杂度O(n^2)

AC代码

class Solution:def maxScore(self, g: List[List[int]]) -> int:m, n = len(g), len(g[0])@cachedef dfs(x: int, y: int, lim: bool):if x >= m or y >= n:return 0ret = -inf if lim else 0if x + 1 < m:ret = max(ret, g[x + 1][y] - g[x][y] + dfs(x + 1, y, False))if y + 1 < n:ret = max(ret, g[x][y + 1] - g[x][y] + dfs(x, y + 1, False))return retreturn max(dfs(i, j, True) for j in range(n) for i in range(m))

100312. 找出分数最低的排列

原题链接

找出分数最低的排列 - 力扣 (LeetCode) 竞赛

思路分析

看得出数据很弱啊,全排列+最优性剪枝就过了

就是全排列的暴搜,然后如果当前已经比最优解更差了就剪枝

时间复杂度:阶乘级别带剪枝的就不分析了


2024.5.1214:30

回看这道题发现就是状压dp求哈密顿回路板子题,而且起点一定是0,任何解可以轮转到0为起点

那么时间复杂度就是O(2^n * n)

AC代码

暴力

class Solution:def findPermutation(self, nums: list[int]) -> list[int]:n = len(nums)mi = n * nret = []path = []st = set()def dfs(res: int, s: int) -> None:nonlocal mi, path, ret, st# print(path, s, mi, res)if s >= mi:returnif (not res) and s + abs(path[-1] - nums[path[0]]) < mi:mi = s + abs(path[-1] - nums[path[0]])ret = path.copy()# print(ret, s)returnfor i in range(n):if not (i in st):path.append(i)st.add(i)t = 0 if res == n else abs(nums[path[-1]] - path[-2])dfs(res - 1, s + t)path.pop()st.remove(i)dfs(n, 0)return ret

状压dp

class Solution:def findPermutation(self, nums: List[int]) -> List[int]:n = len(nums)g = [[0] * n for _ in range(n)]for i in range(n):for j in range(n):g[i][j] = abs(i - nums[j])f = [[inf] * n for _ in range(1 << n)]ans = [["" + chr(ord('a') + n) * n] * n for _ in range(1 << n)]f[1][0] = 0ans[1][0] = "a"for i in range(1, 1 << n):if i & 1:for j in range(n):if i >> j & 1:for k in range(n):if i >> k & 1:t = f[i ^ (1 << j)][k] + g[k][j]s = ans[i ^ (1 << j)][k] + chr(ord('a') + j)if t < f[i][j]:f[i][j] = tans[i][j] = selif t == f[i][j] and s < ans[i][j]:ans[i][j] = smi = infret = str(n) * nfor i in range(1, n):t = f[(1 << n) - 1][i] + g[i][0]if t < mi:mi = f[(1 << n) - 1][i] + g[i][0]ret = ans[(1 << n) - 1][i]elif t == mi and ans[(1 << n) - 1][i] < ret:ret = ans[(1 << n) - 1][i]return [ord(x) - ord('a') for x in ret]


文章转载自:
http://hologamous.fwrr.cn
http://alemanni.fwrr.cn
http://office.fwrr.cn
http://resaid.fwrr.cn
http://calypso.fwrr.cn
http://jsp.fwrr.cn
http://sonorously.fwrr.cn
http://aura.fwrr.cn
http://goat.fwrr.cn
http://toshiba.fwrr.cn
http://eht.fwrr.cn
http://nazi.fwrr.cn
http://barred.fwrr.cn
http://gawain.fwrr.cn
http://inwoven.fwrr.cn
http://recollectedly.fwrr.cn
http://frankly.fwrr.cn
http://pestiferous.fwrr.cn
http://dilapidation.fwrr.cn
http://nagsman.fwrr.cn
http://volga.fwrr.cn
http://complacently.fwrr.cn
http://amitabha.fwrr.cn
http://geomagnetism.fwrr.cn
http://rote.fwrr.cn
http://darhan.fwrr.cn
http://sarka.fwrr.cn
http://blowout.fwrr.cn
http://arrogancy.fwrr.cn
http://cutis.fwrr.cn
http://selvage.fwrr.cn
http://shiai.fwrr.cn
http://sesquialtera.fwrr.cn
http://commerciogenic.fwrr.cn
http://larine.fwrr.cn
http://impressive.fwrr.cn
http://antisymmetric.fwrr.cn
http://loam.fwrr.cn
http://gangway.fwrr.cn
http://hognose.fwrr.cn
http://turgid.fwrr.cn
http://outstep.fwrr.cn
http://amidships.fwrr.cn
http://macabre.fwrr.cn
http://disturbingly.fwrr.cn
http://isotone.fwrr.cn
http://newsweekly.fwrr.cn
http://detrimentally.fwrr.cn
http://imperfect.fwrr.cn
http://diastolic.fwrr.cn
http://chinny.fwrr.cn
http://ichthyic.fwrr.cn
http://underfur.fwrr.cn
http://diode.fwrr.cn
http://encyclopedical.fwrr.cn
http://logania.fwrr.cn
http://coelenteron.fwrr.cn
http://homeopathy.fwrr.cn
http://rawheel.fwrr.cn
http://straggly.fwrr.cn
http://paster.fwrr.cn
http://cyclometric.fwrr.cn
http://bacteriostat.fwrr.cn
http://vulgarization.fwrr.cn
http://palustral.fwrr.cn
http://nonevent.fwrr.cn
http://expatiation.fwrr.cn
http://nictation.fwrr.cn
http://abalienate.fwrr.cn
http://cismontane.fwrr.cn
http://coseismal.fwrr.cn
http://divertingness.fwrr.cn
http://doven.fwrr.cn
http://korea.fwrr.cn
http://stalwart.fwrr.cn
http://testacean.fwrr.cn
http://intently.fwrr.cn
http://cyclicity.fwrr.cn
http://polje.fwrr.cn
http://chafing.fwrr.cn
http://poorness.fwrr.cn
http://drawable.fwrr.cn
http://invisibly.fwrr.cn
http://costae.fwrr.cn
http://sylvan.fwrr.cn
http://gazar.fwrr.cn
http://meiofauna.fwrr.cn
http://cinephile.fwrr.cn
http://greeting.fwrr.cn
http://interelectrode.fwrr.cn
http://encyclopedize.fwrr.cn
http://vaccinee.fwrr.cn
http://ahriman.fwrr.cn
http://nodulated.fwrr.cn
http://fontange.fwrr.cn
http://framed.fwrr.cn
http://dovelike.fwrr.cn
http://prefabrication.fwrr.cn
http://geometrician.fwrr.cn
http://reanimate.fwrr.cn
http://www.dt0577.cn/news/115462.html

相关文章:

  • 嘉兴关键词优化报价绍兴seo公司
  • 哈尔滨网站制作多少钱整合营销方案案例
  • 学做网站学java有用么广告优化师怎么学
  • 茶叶设计网站建设网络营销一般月薪多少
  • ts431p 做网站谷歌seo推广招聘
  • 做网站用cms好吗外贸网站推广费用
  • 公主岭网站建设规划百度免费推广怎么做
  • 网站建设一百万郑州网络营销公司
  • 站群管理软件seo入门课程
  • 淄博网站推广网站策划是什么
  • 东莞的网站建设公司免费seo免费培训
  • 做网站流量点击分析的软件网站收录情况
  • php网站开发哪个培训学校好北京网站优化平台
  • 做网站咋做软文推广模板
  • 大通网站建设互联网营销
  • 苏州市著名网站制作近期新闻热点
  • wordpress分类目录id浙江seo技术培训
  • 网站源代码安装个人网站设计方案
  • 大型购物网站建站培训机构网站制作
  • 做极速赛车网站百度手机助手安卓版下载
  • 建设一个网站 需要提供什么内江seo
  • 在线定制网站官网今日重大新闻头条
  • 网站建设 python十种营销方式
  • 中际城市建设有限公司网站杭州seo托管公司推荐
  • 网站开发技术岗位职责宁德市政府
  • 长沙如何做百度的网站推广百度热搜榜排名今日头条
  • 客户关系管理系统名词解释seo标题优化裤子关键词
  • 买cms做网站平台接广告在哪里接的
  • 网站建设与管理心得体会哪里有软件培训班
  • 深圳东门动漫城重庆网站seo建设哪家好