How to find n elements from the list of components specified amount?


Required to solve the problem with the following data:
  • A list of limited number of integers (up to 100), for example [102, 154, 310, 140, 250, 70, 120]
  • Number like 700

These data need to find the only set of the n-th number of the numbers from the list whose sum is closest to a given number or equal to it.

Or need description of the algorithm, or, at best, ready-made solution (preferably python).
July 8th 19 at 15:36
1 answer
July 8th 19 at 15:38
for the smartest


the problem in General has no solution, by the way
the proposed solution (the classical "knapsack" problem) was considered earlier, but in the absence of numbers of weight, the algorithm will simply offer a large amount of items that a certain degree of probability may be the type of answer sought, but will not solve the task with the necessary conditions. - dana.Breitenberg48 commented on July 8th 19 at 15:41

Find more questions by tags Algorithms