此問題被稱爲MINIMUM ķ -union,並且它是NP-hard,如下所示:
因此,沒有人知道任何算法來解決它在時間上運行的多項式大小的輸入。
在你的情況,你可能會很樂意接受的近似解:即用成分的小工會食譜的集合,但不一定是最小的這樣的集合。所以我建議你試試貪心算法:通過在每個階段加入,該聯盟的規模最小的配方反覆建立食譜的集合。下面是Python中的天真實現:
def small_union(sets, k):
"""
Choose `k` elements from `sets` and return their union. Attempt
to return a fairly small union using a greedy approach.
>>> small_union([{1,2}, {2,3}, {1,2,3}, {1}, {2}], 3)
set([1, 2])
>>> small_union([{1,2}, {2,3}, {3,4}, {1,4}], 3)
set([1, 2, 3, 4])
"""
union = set()
for _ in xrange(k):
s = min(sets, key = lambda s: len(s | union))
sets.remove(s)
union |= s
return union
嗯也許Mathforum會更好;) –
跨張貼在這裏:http://mathoverflow.net/questions/259485/inverse-set-cover-problem(2017) –
爲O(n^{0.25+ \小量}) - 近似算法在這裏(和SODA 2017年):https://arxiv.org/abs/1611.07866 –