随笔分类 - 动态规划
摘要:problem: https://leetcode.com/problems/knight-probability-in-chessboard/ This is an easy problem using dfs.
阅读全文
摘要:problem:https://leetcode.com/problems/count-numbers-with-unique-digits/ 1 : 10 2: 10 + 9 x 9 3: 10 + 9 x 9 + 9 x 9 x 8 4: 10 + 9 x 9 + 9 x 9 x 8 x 7 …
阅读全文
摘要:problem:https://leetcode.com/problems/russian-doll-envelopes/ 最长连续子序列类型问题。先排序,dp[i]记录使用第i个套娃的最大数量。
阅读全文
摘要:problem:https://leetcode.com/problems/integer-break/ 枚举所有整数相加,取它们最大乘积的乘积,然后选择最大值。
阅读全文
摘要:problem:https://leetcode.com/problems/counting-bits 爬台阶类型。我的做法是num拆分为比它小的最大2^n的值加上另一个数,然后这两个的dp叠加。
阅读全文
摘要:problem:https://leetcode.com/problems/create-maximum-number/ 分治。计算第一个数组最大的和第二个数组最大的,然后结合起来找最大的。
阅读全文
摘要:problem:https://leetcode.com/problems/perfect-squares 数字类dp。查找当前数字减去一个平方数对应的最小拆分次数。
阅读全文
摘要:problem: https://leetcode.com/problems/ugly-number-ii 大的ugly number是由小的ugly number乘以系数2, 3, 5得到的,每次相乘后,取最小的作为下一个,然后把最小的值的当前指针向后挪一位。(用vector封装了一下速度更慢了,
阅读全文
摘要:problem: https://leetcode.com/problems/house-robber-ii/ 多状态转换dp。我的方法是维护了四个状态。用两趟dp的基本思想也是多个状态。
阅读全文
摘要:problem:https://leetcode.com/problems/dungeon-game 看了这道题的tag我用了二分 + 简化dp(只需求特定血量能否达到)来做,能过但是速度好慢。一看评论区发现大家都是用纯dp过的,我哭了。
阅读全文
摘要:problem:https://leetcode.com/problems/maximum-product-subarray 类似买卖股票,需要维护两个状态,当前最大数和最小数。
阅读全文
摘要:problem:https://leetcode.com/problems/word-break/ 划分类型问题。
阅读全文
摘要:problem:https://leetcode.com/problems/palindrome-partitioning-ii/ 爬台阶类型问题。先计算出所有可能的回文串,dp[ i ] 代表前 i 个字符的最小划分,找到以 i 结尾的所有回文串,取划分最小的那个作为结果。
阅读全文
摘要:problem:https://leetcode.com/problems/distinct-subsequences/ 字符匹配类型题目。
阅读全文
摘要:problem:https://leetcode.com/problems/wildcard-matching/ 用记忆化搜索做的,不容易出错: 非递归:
阅读全文
摘要:problem:https://leetcode.com/problems/unique-binary-search-trees/ 左子树个数 * 右子树个数
阅读全文
摘要:problem:https://leetcode.com/problems/unique-binary-search-trees-ii/ 用递归传最小值和最大值写起来代码应该会更简练,此处用的是递推写的。
阅读全文
摘要:problem:https://leetcode.com/problems/unique-paths-ii 爬台阶类型问题(2D), 如果当前位置有障碍物就不进行状态转换。
阅读全文
摘要:problem:https://leetcode.com/problems/longest-string-chain/ 爬台阶类型问题。从长度为k转换为长度为k + 1的字符串。此处通过删掉一个字符,查看删掉后的字符串是否存在来判断能否转换。
阅读全文
摘要:problem:https://leetcode.com/problems/partition-equal-subset-sum/ 经典背包问题。找到是否存在恰好装满sum / 2的物体,可以优化为1D的。
阅读全文

浙公网安备 33010602011771号