Recursive implementation of a knapsack algorithm (top-down approach)