improve code
knapsack problem via dynamic prog