given N absolute values of integers find the combination of N/2 negative and N/2 positive values whose sum is closest to 0

后端 未结 5 1471
隐瞒了意图╮
隐瞒了意图╮ 2021-01-21 04:36

Let\'s say that I have an array of 10 numbers whose absolute value range can go from 1 to 10. Values can be repeated. An example of this could be

{2, 4, 2, 6, 9         


        
5条回答
  •  耶瑟儿~
    2021-01-21 05:14

    Welcome to the world of the NP-class problems!

    You can compute the optimal solution by bruteforce or trying a relaxed approach (like the simplex algorithm) which will bring you the solution in polinomial time on the average-case complexity

提交回复
热议问题