# Multiple Constraint Knapsack Problem Dynamic Programming

Is there any way for solving the Knapsack problem when we are limited by several constraints?

Let's assume that we have a set of items in which we have value v that we want to maximize and we also have two constraints weight and volume that must be lower or equal than the values W and V respectively.

My question is, can this problem be solved using dynamic programming?

• Welcome to CS.SE! What have you tried? Have you tried adapting the dynamic programming algorithm for standard knapsack? The answer is yes, you can adapt it, and if you understand how that algorithm works, it should be pretty straightforward. – D.W. Oct 30 '16 at 17:45
• I have not implemented anything yet, I am trying to understand what to do. My initial guess if the solution for 1 constraint is a 2D-Matrix in which the rows(x-axis) indicate the item number and columns(y-axis) the available weight then in order to implement with 2-constraints I should have a 3D-Matrix in which the matrix deep(z-axis) will be the available volume. Do you thing that I am in the good way in order to solve it? – Adrian Gallego Castellanos Oct 30 '16 at 20:48

The idea in your comment (add one more dimension to the dynamic programming table) is essentially correct. In the classic knapsack, for any $$i=0,\ldots,n$$ and $$w=0,\ldots,W$$, you compute the highest profit that you can get with items of type $$\le i$$ and total weight $$\le w$$ (so you can get an $$O(nW)$$ time algorithm). In the generalization, you also need to iterate on the total volume $$v=0,\ldots,V$$, which means an $$O(n W V)$$ time algorithm.