adding memory improvements for knapsack, use only 3 rows in matrix to store values