Algorithm to pick values from array that sum closest to a target value?

前端 未结 3 1178
遥遥无期
遥遥无期 2020-12-04 03:19

I have an array of nearly sorted values 28 elements long. I need to find the set of values that sums to a target value provided to the algorithm (or if exa

3条回答
  •  盖世英雄少女心
    2020-12-04 03:51

    This problem is known as the subset sum problem, which is a special case of the Knapsack problem. Wikipedia is a good starting point for some algorithms.

提交回复
热议问题