Python Code:
import itertools
w=['a','a','a','b','b','b','c','d','e','e']
num=list(set(itertools.permutations(w))) #排列並去除相同元素
other=[]
for i in range(len(num)):
for j in range(len(num[0])-1):
if (num[i][j]=='a' and num[i][j+1]=='b') or \
(num[i][j]=='b' and num[i][j+1]=='a'):
other.append((num[i]))
ans=set(num)-set(other)
print(ans)
print(len(ans))
答案:4080種
沒有留言:
張貼留言