The Knapsack Problem
Let's apply what we're learned so far to a slightly more interesting
problem. You are an art thief who has found a way to break into the
impressionist wing at the Art Institute of Chicago. Obviously you can't
take everything. In particular, you're constrained to take only what
your knapsack can hold — let's say it can only hold W pounds. You also
know the market value for each painting. Given that you can only carry W
pounds what paintings should you steal in order to maximize your
profit?
First let's see how this problem exhibits both overlapping subproblems
and optimal substructure. Say there are n paintings with weights w1
, ..., wn
and market values v1
, ..., vn
.
Define A(i,j) as the maximum value that can be attained from
considering only the first i items weighting at most j pounds as
follows.
Obviously A(0,j) = 0 and A(i,0) = 0 for any i ≤ n and j ≤ W. If wi
> j then A(i,j) = A(i-1, j) since we cannot include the ith
item. If, however, wi
≤ j then A(i,j) then we have a choice: include the ith
item or not. If we do not include it then the value will be A(i-1, j). If we do include it, however, the value will be vi
+ A(i-1, j - wi
). Which choice should we make? Well, whichever is larger, i.e., the maximum of the two.
Expressed formally we have the following recursive definition
This problem exhibits both overlapping subproblems and optimal
substructure and is therefore a good candidate for dynamic programming.
The subproblems overlap because at any stage (i,j) we might need to
calculate A(k,l) for several k < i and l < j. We have optimal
substructure since at any point we only need information about the
choices we have already made.
http://20bits.com/article/introduction-to-dynamic-programming
分享到:
相关推荐
在本文中,作者提出了一种改进的混合遗传算法(Hybrid Genetic Algorithm, HGA)来解决多约束0-1背包问题(Multiconstrained 0-1 Knapsack Problem, MKP)。MKP是一个著名的NP完全组合优化问题,其定义如下: 目标...
背包问题:经典背包问题(Knapsack Problem)的Java和Python实现; 背包问题:经典背包问题(Knapsack Problem)的Java和Python实现; 背包问题:经典背包问题(Knapsack Problem)的Java和Python实现; 背包问题:...
背包问题近似算法PTAS和FPTAS. The Knapsack Problem and Fully Polynomial Time Approximation Schemes (FPTAS). 作者: Katherine Lai, Prof. M. X. Goemans
0/1背包问题
java动态规划算法
背包问题(Knapsack Problem)是运筹学中的一个经典优化问题,广泛应用于资源分配、项目选择等场景。它涉及到在一个容量有限的背包中,如何选取物品以使总价值最大。这个问题的复杂性在于物品的重量和价值之间存在...
背包问题(Knapsack Problem)是运筹学中的一个经典问题,属于组合优化的范畴。它描述了这样一个场景:有一组物品,每种物品都有自己的重量和价值,我们需要在给定的背包容量限制下,选择物品以最大化总价值。这个...
c++ knapsack problem
01背包问题(0/1 Knapsack Problem)是一个经典的动态规划问题,其描述为:给定一个固定容量的背包和一组物品,每个物品有对应的重量和价值,要求在不超过背包容量的情况下,装入背包的物品总价值最大。 定义了一个...
Knapsack_Problem In Matlab
Genetic Algorithm for multi objective knapsack problem
背包问题,又称Knapsack Problem,是运筹学中一个经典的优化问题,广泛应用于资源分配、项目投资等领域。该问题的基本设定是:有一组物品,每种物品都有重量和价值,我们需要在不超过背包容量的前提下,选择物品以...
genetic Approach For Solving Knapsack_Problem
背包问题(Knapsack problem)是一种组合优化的NP完全问题
背包问题(Knapsack Problem)是计算机科学和运筹学领域中的一个经典问题,属于组合优化的一种。该问题的主要目标是在一定的约束条件下(如背包的容量),通过选择一系列物品来最大化某个指标(通常是价值)。根据...
【标题】:背包问题(Knapsack Problem) 【描述】:背包问题是一个经典的组合优化问题,在计算机科学和运筹学中广泛存在。该问题的基本设定是:有一个容量有限的背包,以及一系列具有不同价值和重量的物品。目标是...
背包问题(Knapsack problem)是一种组合优化的NP完全问题。问题可以描述为:给定一组物品,每种物品都有自己的重量和价格,在限定的总重量内,我们如何选择,才能使得物品的总价格最高。问题的名称来源于如何选择最...