python3 求一个list的所有子集

def PowerSetsBinary(items):
    N = len(items)
    for i in range(2 ** N):#子集的个数
        combo = []
        for j in range(N):#用来判断二进制数的下标为j的位置的数是否为1
            if (i >> j) % 2:
                combo.append(items[j])
        print(sum(combo))
        print(combo,"\n")

        
L = [100000,12844.26,11393.83,14819.92,747.04,843,30435.12,3628.48,40856.32,12326.16,20259.01,16360.18,26146.4,4268.8,6403.2,5015.84,41366.51,6819.48,15061.12,31887.67,28590.49,63716.64,9469.35,12749.43,16346.4,100000,23557.22,1067.2,192.1,533.6]
print(round(sum(L),2))
#PowerSetsBinary(L)

 

相关文章:

  • 2022-12-23
  • 2021-09-07
  • 2021-07-14
  • 2022-12-23
  • 2021-12-19
  • 2021-11-02
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-04
  • 2022-12-23
  • 2022-12-23
  • 2022-03-05
  • 2022-12-23
  • 2022-01-01
  • 2022-01-01
相关资源
相似解决方案