全组合

作者: hops | 来源:发表于2017-07-21 19:30 被阅读3次

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

相关文章

网友评论

      本文标题:全组合

      本文链接:https://www.haomeiwen.com/subject/iqaekxtx.html