背包问题 (Knapsack problem
- 背包问题 Knapsack problem
-
- 一、01 背包
- [2915. 和为目标值的最长子序列的长度](https://leetcode.cn/problems/length-of-the-longest-subsequence-that-sums-to-target/)
- [416. 分割等和子集](https://leetcode.cn/problems/partition-equal-subset-sum/)
- [1049. 最后一块石头的重量 II](https://leetcode.cn/problems/last-stone-weight-ii/)
- [★ 2742. 给墙壁刷油漆](https://leetcode.cn/problems/painting-the-walls/)
- [★ 494. 目标和](https://leetcode.cn/problems/target-sum/)
- 二、完全背包
- [322. 零钱兑换](https://leetcode.cn/problems/coin-change/description/)
- [279. 完全平方数](https://leetcode.cn/problems/perfect-squares/description/)
- [518. 零钱兑换 II](https://leetcode.cn/problems/coin-change-ii/)
- [377. 组合总和 Ⅳ](https://leetcode.cn/problems/combination-sum-iv/description/)
- [139. 单词拆分](https://leetcode.cn/problems/word-break/)
- [474. 一和零](https://leetcode.cn/problems/ones-and-zeroes/)
- [879. 盈利计划](https://leetcode.cn/problems/profitable-schemes/)
- [805. 数组的均值分割](https://leetcode.cn/problems/split-array-with-same-average/)
- 三、多重背包
- [30. 串联所有单词的子串](https://leetcode.cn/problems/substring-with-concatenation-of-all-words/)
- [1787. 使所有区间的异或结果为零](https://leetcode.cn/problems/make-the-xor-of-all-segments-equal-to-zero/)
- [2518. 好分区的数目](https://leetcode.cn/problems/number-of-great-partitions/)
- [1774. 最接近目标价格的甜点成本](https://leetcode.cn/problems/closest-dessert-cost/)
- 四、分组背包
- [1155. 掷骰子的N种方法](https://leetcode.cn/problems/number-of-dice-rolls-with-target-sum/)
- [2218. 从栈中取出 K 个硬币的最大面值和](https://leetcode.cn/problems/maximum-value-of-k-coins-from-piles/)
- 2915. 和为目标值的最长子序列的长度 1659
- 顺丰 02. 小哥派件装载问题
- 416. 分割等和子集
- 494. 目标和
- 2787. 将一个数字表示成幂的和的方案数 1818
- 474. 一和零(二维)
- 1049. 最后一块石头的重量 II 2092
- 1774. 最接近目标价格的甜点成本
- 879. 盈利计划 2204
- 3082. 求出所有子序列的能量和 ~2300
- 956. 最高的广告牌 2381
- 2518. 好分区的数目 2415
- 2742. 给墙壁刷油漆 2425
- LCP 47. 入场安检
- 322. 零钱兑换
- 518. 零钱兑换 II
- 279. 完全平方数
- 1449. 数位成本和为目标值的最大数字 1927 打印方案
- 2585. 获得分数的方法数 1910
- 2902. 和带限制的子多重集合的数目 2759
- 1155. 掷骰子等于目标和的方法数 1654
- 1981. 最小化目标值与所选元素的差 2010
- 2218. 从栈中取出 K 个硬币的最大面值和 2158
背包问题 Knapsack problem
动态规划 是运筹学的一种最优化方法,核心是 穷举。
存在「重叠子问题」、具备「最优子结构」(子问题互相独立)和「无后效性」。
递归解法「自顶向下」;动态规划「自底向上」dp 数组的 迭代解法。
背包问题是经典的「动态规划」,本质上属于 组合优化的「 NP完全问题」,「无法直接求解」的问题,只能通过 「穷举」+「验证」 的方式进行求解。