Lets assume that we have only integer numbers which values are in range 1
to N
. Next we will split them into K-element
multi-sets. How would you find such set which contains smallest possible number of those multi-sets yet sum of this multi-set contains all numbers from 1
to N
? In case of ambiguity answer will be any set that matches criteria (first found).
For instance, we have N = 9
, K = 3
(1,2,3)(4,5,6)(7,8,8)(8,7,6)(1,9,2)(4,4,3)
Smallest number of multi-sets that contains all the numbers from 1
to 9
is equal to 4
and can be either (1,2,3)(4,5,6)(7,8,8)(1,9,2)
or (1,2,3)(4,5,6)(8,7,6)(1,9,2)
.
Any idea for efficient algorithm to find such set?
PS
After writing an answer I found yet another 4
element set: (4,5,6)(1,9,2)(4,4,3)(7,8,8)
or (4,5,6)(1,9,2)(4,4,3)(8,7,6)
But as I said algorithm finding any minimum set would be fine.
Answers
Your question is a restricted version the classic Set Covering problem, but it still easy to show that it is NP-Hard.
Any approximation technique for this problem would be reasonable here. In particular, the greedy solution of choosing the next subset covering the most uncovered items - is esp. easy to implement.
Answers
This problem, as @Ami Tavroy said, is NP-hard by reduction to 3-dimensional matching (here).
To do the reduction, note the restricted decision variant of 3-dimensional matching when it reduces to a exact cover (here):
...given a set T and an integer k, decide whether there exists a
3-dimensional matching M ⊆ T with |M| ≥ k. ... The problem is
NP-complete even in the special case that k = |X| = |Y| =
|Z|.1[4][5] In this case, a 3-dimensional (dominating) matching is
not only a set packing but also an exact cover: the set M covers each
element of X, Y, and Z exactly once.[6]
This variant can be solved in P if you can solve the other question in P - you can produce all the triples in O(N ^ 3)
time and then do set cover, and check if K = N / 3
or not. Thus by reduction, the original questions is also NP-hard.
コメント