python实现
ans=0
def search(num=0,lst=[]):
if(num==8):
global ans
ans+=1
print(lst)
print("ans=",ans)
else:
for i in range(8):
ok=True
for j in lst:
if(i==j[1] or (i+num)==(j[0]+j[1]) or (num-i)==(j[0]-j[1])):
ok=False
break
if ok:
lst.append((num,i))
search(num+1,lst)
lst.pop()
search(0)
Comments NOTHING