Last active
December 24, 2016 19:47
-
-
Save rashedcs/7ac235b224b7bb4a8db552fdd89dc0ea to your computer and use it in GitHub Desktop.
This file contains hidden or 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
int N, V[100], W[100], memo[100][100]; | |
int value(int id, int w) | |
{ | |
if (memo[id][w] != -1) return memo[id][w]; //Memoization | |
if (id == N || w == 0) return 0; //Base Case | |
else if (W[id] >w) return memo[id][w] = value(id + 1, w); | |
else return memo[id][w] = max(value(id + 1, w), V[id] + value(id + 1, w - W[id])); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment