Last active
November 23, 2016 15:00
-
-
Save felipecruz/1bb22a5ed49187a1630ab100a3420877 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Input: | |
// Values (stored in array v) | |
// Weights (stored in array w) | |
// Number of distinct items (n) | |
// Knapsack capacity (W) | |
for j from 0 to W do: | |
m[0, j] := 0 | |
for i from 1 to n do: | |
for j from 0 to W do: | |
if w[i] > j then: | |
m[i, j] := m[i-1, j] | |
else: | |
m[i, j] := max(m[i-1, j], m[i-1, j-w[i]] + v[i]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment