我想解决以下类型的最小集合覆盖问题。所有列表仅包含 1 和 0。
我说,如果你可以通过插入精确的符号来制作A列表,那么列表就覆盖了列表。 BBAx
考虑所有 2^n 个长度为 1 和 0 的列表n并设置x = n/3。我想计算一组最小长度的列表2n/3我会计算一组涵盖所有
这是我开始采用的一种幼稚的方法。对于每个可能的长度列表,2n/3我创建一组可以使用此函数(由 DSM 编写)从中创建的所有列表。
from itertools import product, combinations
def all_fill(source, num):
output_len = len(source) + num
for where in combinations(range(output_len), len(source)):
# start with every possibility
poss = [[0,1]] * output_len
# impose the source list
for w, s in zip(where, source):
poss[w] = [s]
# yield every remaining possibility
for tup …Run Code Online (Sandbox Code Playgroud)