标签:
pos=[0]*5
x=[0]*5
def place(t):
for i in range(1,t):
if (pos[i] == pos[t]):
return False
elif (abs(pos[i]-pos[t]) == abs(i-t)):
return False
return True
def Backtrack(t,n):
if (t>n):
print "get an answer"
print pos
else:
for i in range(1, n+1):
pos[t]=i
if (place(t)):
Backtrack(t+1, n)
def Queen(n):
Backtrack(1,n)
Queen(4)
标签:
原文地址:http://www.cnblogs.com/zhaodonglin/p/5445018.html