|
发表于 2020-8-10 12:46:10
|
显示全部楼层
result=[]
def main():
test_list=[2,5,8]
ll=len(test_list)
#cal(test_list,ll,0)
for i in range(1,2**ll):
choice=choose(i,ll)
test1=[]
for j in range(ll):
if choice[j]!=0:
test1.append(test_list[j])
cal(test1,len(test1),0)
print(sum(result))
def cal(test_list,n,x):
for i in range(n):
if n==1:
result.append(test_list[i]+10*x)
break
else:
y=test_list[i]+10*x
test1=test_list[:i]+test_list[i+1:]
cal(test1,n-1,y)
def choose(n,ll):
list1=[0]*ll
for i in range(ll):
list1[i]=n%2
n=n//2
return list1
if __name__=="__main__":
main()
不知道这个符不符合楼主的要求 |
|