glennbh
glennbh
全部文章
分类
题解(1)
归档
标签
去牛客网
登录
/
注册
glennbh的博客
全部文章
(共7篇)
题解 | #下一个排列#
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param nums int整型一维数组 # @return(756076230) int整型一维数组 # class Solution: def nextPermutation(self ,...
2023-02-02
0
353
题解 | #【模板】单源最短路2#
# bfs import math class Solution: def slove(self, n: int, m: int, links: List[List[int]]) -> int: if n == 1: return 0 ...
2023-01-21
0
257
题解 | #最小生成树#
#一定要注意,去掉指向自身节点的边,被坑了一天#class Solution: def miniSpanningTree(self , n: int, m: int, cost: List[List[int]]) -> int: # write code here ...
2023-01-21
0
324
题解 | #【模板】01背包#
# 状态定义:dp1[i]表示不考虑背包是否装满,在容量为i的情况下,最多装多大价值的物品。 # 状态转移:遍历所有的物品,要么选择当前物品,要么不选,取价值最大的,并且通过这种方式跟新所有情况的状态。即 # dp1[j]=Math.max(dp1[j−v[i]]+w[i],dp1[j]) # ...
2023-01-21
0
346
题解 | #快速幂#
class Solution: def solve(self, a: int, b: int, p: int): result = 1 smod = a % p runnum = b while runnum > 0...
2023-01-20
0
301
题解 | #ranko的手表#
import sys class Solution: def solve(self, str1: str, str2:str) -> (int, int): hour1 = str1.split(":")[0] minute1 = str1.spli...
2023-01-19
0
322
题解 | #不相邻最大子序列和#
Python2 解题 令 dp[i]=[a ,b]a 表示是否使用第i个数字b 表示前i个数组成的序列的最大和 动态规划的每一步需要分类讨论如果dp[i-1]没有使用第i-1个数字(dp[i-1][0]==False),则看 dp[i-1], dp[i-1]+array[i], array[i] 哪...
算法笔试
动态规划
2021-05-30
0
494