implementing knapsack