knapsack algorithm implemenatation