Exercise 4. Knapsack problem first implementation.