资源 · 指南或文章
Knapsack Problem
背包问题及其主要变体的形式化定义,适合在动态规划类问题之前作为背景知识。
审核日期
打开原站: Knapsack Problem (在新标签页中打开原网站)添加到路线图
把这个资源放进你正在跟进的路线图。它会作为你自己的补充资源显示;路线图的步骤不会改变,也不计入你已记录的步骤。
来源内容语言:英语
The knapsack problem or rucksack problem is a problem in combinatorial optimization: Given a set of items, each with a weight and a value, determine the number of each item to include in a collection so that the total weight is less than or equal to a given limit and the total value is as large as possible. It derives its name from the problem faced by someone who is constrained by a fixed-size knapsack and must fill it with the most valuable items. Example of a one-dimensional (constraint) knapsack problem: which boxes should be chosen to maximize the amount of money while still keeping the overall weight under or equal to 15 kg?
PrepKit 概览
本概览由 PrepKit 编辑根据源代码仓库撰写并审核,并非资源本身的文字。
- 适合人群
- 来源未说明适用级别
- 形式
- 参考资料
涵盖内容
- 优化目标,以及一个 15 公斤箱子的例子。
- 0/1 背包问题:每件物品取零次或一次。
- 有界背包问题:每件物品最多取 c 件。
- 无界背包问题:每件物品可取任意非负数量。
使用建议
这是 PrepKit 的学习建议,并非来源的说法。
手动为四件物品构建 0/1 背包的 DP 表,然后编写代码,并解释无界版本如何改变循环。
范围与局限
只有定义:没有讲解求解方法或复杂度。公式是图片,内容依赖维基百科和一个 YouTube 视频。
获取方式与形式
GitHub 上的英文 README,免费,位于采用 MIT 许可的 trekhleb/javascript-algorithms 项目。
PrepKit 于 2026年10月2日 审核。 资源来源提交: 85293e3e2b88
本概览的依据
- src/algorithms/sets/knapsack-problem/README.md
收录此条目的页面
订阅 PrepKit 通讯
可选。使用 PrepKit 并不需要订阅。