Knapsack problem (calculate the capacity of a backpack)