Skip to content

Instantly share code, notes, and snippets.

@rashedcs
Last active December 24, 2016 19:47
Show Gist options
  • Save rashedcs/7ac235b224b7bb4a8db552fdd89dc0ea to your computer and use it in GitHub Desktop.
Save rashedcs/7ac235b224b7bb4a8db552fdd89dc0ea to your computer and use it in GitHub Desktop.
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