Memory inefficient code for dp knapsack