摘要:
https://leetcode.cn/problems/coin-change/description/ 代码上比较麻烦的dp题,由于求的是最少数量,因此求答案时需要初始化无穷大来计算 class Solution { public int coinChange(int[] coins, int 阅读全文
posted @ 2024-09-03 21:01
风乐
阅读(15)
评论(0)
推荐(0)
摘要:
https://leetcode.cn/problems/combination-sum-iv/description/ 此篇题解解释了为什么不能直接用二维完全背包的方式做不过还是建议把这个题当成一个爬楼梯来做 class Solution { public: int combinationSum4 阅读全文
posted @ 2024-09-03 19:35
风乐
阅读(16)
评论(0)
推荐(0)
摘要:
https://leetcode.cn/problems/coin-change-ii/description/可以直接考虑用完全背包的传统二维做法,但是这里求的是组合数,需要注意 在求装满背包有几种方案的时候,认清遍历顺序是非常关键的。 如果求组合数就是外层for循环遍历物品,内层for遍历背包。 阅读全文
posted @ 2024-09-03 16:55
风乐
阅读(9)
评论(0)
推荐(0)
摘要:
https://leetcode.cn/problems/ones-and-zeroes/solutions/ 多重体积的01背包,关键是需要想到把构造这个最长子集 等价为 往一个背包里塞物品,求能塞最多的物品是多少?且这里有两层体积这样想就能转化为01背包了,即f[i][j][k]表示在前i个物品 阅读全文
posted @ 2024-09-03 03:19
风乐
阅读(28)
评论(0)
推荐(0)
摘要:
https://leetcode.cn/problems/target-sum/solutions/2119041/jiao-ni-yi-bu-bu-si-kao-dong-tai-gui-hua-s1cx/ 灵神的代码实现比我自己写的更好,可以多学习学习这道题的关键点在于想到 正数和+负数和=ta 阅读全文
posted @ 2024-09-03 02:15
风乐
阅读(31)
评论(0)
推荐(0)

浙公网安备 33010602011771号