好友
阅读权限10
听众
最后登录1970-1-1
|
[Python] 纯文本查看 复制代码 # -*- coding: utf-8 -*-
"""
Created on Sat Apr 2 04:32:16 2022
@author: fuwen
"""
import itertools
goods = '0AB' #0为空包
Num = 5
g = list(itertools.product(goods, repeat=Num))
g = [i for i in g if list(i).count('A')<3 if list(i).count('B')<4 ] #缩减计算
ng = [] #一个包裹的所有可能
for i in g:
i = sorted(i)
if i not in ng:
ng.append(i)
gl = list(itertools.product(ng, repeat=Num))
gg = []
for k in gl:
k= sorted(k)
if str(k).count('A') ==2 and str(k).count('B') ==3:
if k not in gg:
gg.append(k)
result = []
for s in gg:
s = sorted(s)
if s not in result:
result.append(s)
for p in result:
bags = ''
for c in p:
c = ''.join(c)
c = c.replace('0', '')
bags = bags+c+','
print(bags.strip(','))
>>>
AABBB
A,ABBB
B,AABB
AA,BBB
AB,ABB
BB,AAB
A,A,BBB
A,B,ABB
A,AB,BB
B,B,AAB
B,AA,BB
B,AB,AB
A,A,B,BB
A,B,B,AB
B,B,B,AA
A,A,B,B,B
16看起来是对的…… |
|