1 Star 0 Fork 79

zhizou/javascript-algorithms

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
.github
.husky
assets
src
algorithms
cryptography
graph
image-processing
linked-list
math
ml
search
sets
cartesian-product
combination-sum
combinations
fisher-yates
knapsack-problem
__test__
Knapsack.js
KnapsackItem.js
README.md
longest-common-subsequence
longest-increasing-subsequence
maximum-subarray
permutations
power-set
shortest-common-supersequence
sorting
string
tree
uncategorized
data-structures
playground
utils/comparator
.babelrc
.editorconfig
.eslintrc
.gitignore
.npmrc
BACKERS.md
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE
README.ar-AR.md
README.es-ES.md
README.fr-FR.md
README.id-ID.md
README.it-IT.md
README.ja-JP.md
README.ko-KR.md
README.md
README.pl-PL.md
README.pt-BR.md
README.ru-RU.md
README.tr-TR.md
README.uk-UA.md
README.zh-CN.md
README.zh-TW.md
jest.config.js
package-lock.json
package.json
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

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?

knapsack problem

Definition

0/1 knapsack problem

The most common problem being solved is the 0/1 knapsack problem, which restricts the number xi of copies of each kind of item to zero or one.

Given a set of n items numbered from 1 up to n, each with a weight wi and a value vi, along with a maximum weight capacity W,

maximize 0/1 knapsack

subject to 0/1 knapsack and 0/1 knapsack

Here xi represents the number of instances of item i to include in the knapsack. Informally, the problem is to maximize the sum of the values of the items in the knapsack so that the sum of the weights is less than or equal to the knapsack's capacity.

Bounded knapsack problem (BKP)

The bounded knapsack problem (BKP) removes the restriction that there is only one of each item, but restricts the number xi of copies of each kind of item to a maximum non-negative integer value c:

maximize bounded knapsack

subject to bounded knapsack and bounded knapsack

Unbounded knapsack problem (UKP)

The unbounded knapsack problem (UKP) places no upper bound on the number of copies of each kind of item and can be formulated as above except for that the only restriction on xi is that it is a non-negative integer.

maximize unbounded knapsack

subject to unbounded knapsack and unbounded knapsack

References

马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/zhizous/javascript-algorithms.git
git@gitee.com:zhizous/javascript-algorithms.git
zhizous
javascript-algorithms
javascript-algorithms
master

搜索帮助