全组合

def fc(n):
'''find full combinations for 1-n,
using bitmap method. '''

comb = []
for i in range(2**n-1, 0, -1):
    b = str(bin(i))[2:].zfill(n)
    out = [range(1, n+1)[int(k)] for k, j in enumerate(b) if j == '1']
    comb.append(out)

return comb

你可能感兴趣的:(全组合)