Solution of the knapsack problem