题目:    代码:
import itertools
count=0
a=[1,2,3,4,6,7,8,9,11,12,13,14]
b=list(itertools.combinations(a,5))
def isLiant(x):
q=[]
q.append(x[0])
seen=set()
seen.add(x[0])
while len(q)>0:
n=q.pop(0)
if n-1 in x and n-1 not in seen:
q.append(n-1)
seen.add(n-1)
if n+1 in x and n+1 not in seen:
q.append(n+1)
seen.add(n+1)
if n-5 in x and n-5 not in seen:
q.append(n-5)
seen.add(n-5)
if n+5 in x and n+5 not in seen:
q.append(n+5)
seen.add(n+5)
if set(seen)==set(x):
return 1
else:
return 0
for i in b:
count+=isLiant(i)
print(count)
结果:116
|