动态规划算法——背包问题(Dynamic Programming Algorithm - Knapsack Problem)
背包问题(Knapsack Problem)
(picture is from https://en.wikipedia.org/wiki/Knapsack_problem)
The knapsack problem is a problem in combinatorial optimisation: given n items, each with a weight and a value. Find the most valuable selection of items that will fit in the knapsack.
As shown in the picture,
knapsack capacity: 15 kg
weights: 1, 12, 2, 1, 4 kg
values: 2, 4, 2, 1, 10 dollars
If we choose the yellow, grey, blue and orange items, it will create the value of 2+2+1+10=15 dollars and has a weight of 8kg less than knapsack capacity. This is the most valuable selection.
How can we find the most valuable selection?
方法一 暴力破解(Brute force)
Here is an example. We find all combinations of items and then compute its sum of weights and values.

本文介绍了背包问题的动态规划算法解决方案。通过示例解释了如何利用动态规划找到最优化的选择,以达到在不超过背包容量的情况下,选取价值最大的物品组合。并给出了算法的时间复杂度及伪代码。
最低0.47元/天 解锁文章
555

被折叠的 条评论
为什么被折叠?



