Linear algorithm to find minimum subset sum over a threshold

前端 未结 2 682
孤城傲影
孤城傲影 2021-01-14 18:04

I have a collection of N positive integers, each bounded by a (relatively small) constant C. I want to find a subset of these numbers with the smallest sum greater than (or

2条回答
  •  灰色年华
    2021-01-14 18:45

    Pisinger's algorithm gives you the largest sum less than or equal to the capacity of the knapsack. To solve your problem, use Pisinger to figure out what not to put in the subset. Formally, let the items be w_1, ..., w_n and the minimum be K. Give w_1, ..., w_n and w_1 + ... + w_n - K to Pisinger, then take every item that Pisinger does not.

提交回复
热议问题