leetcode python 037 求解数独
2021-07-15 19:08
标签:port list int code sha get def shape limit import numpy as np def get1(n): def get2(n): def get3(arr,i,j): def sd(arr,dep): leetcode python 037 求解数独 标签:port list int code sha get def shape limit 原文地址:https://www.cnblogs.com/offline-ant/p/9535804.html
import sys
sys.setrecursionlimit(1000) #例如这里设置为一百万
if n return 0
if n return 3
return 6
if n return 3
if n return 6
return 9
a1=list(arr[i,:])
a2=list(arr[:,j])
a3=list(arr[get1(i):get2(i),get1(j):get2(j)].reshape(1,-1)[0])
a=set(a1+a2+a3)
return b-a
count[0]+=1
if dep==len(l):
result.append(arr)
else:
x,y=l[dep]
lac=get3(arr,x,y)
if len(lac)>0 and len(result)==0:
for i in lac:
ac=arr.copy()
ac[x,y]=i
sd(ac,dep+1)
array= [[5,3,0,0,7,0,0,0,0],
[6,0,0,1,9,5,0,0,0],
[0,9,8,0,0,0,0,6,0],
[8,0,0,0,6,0,0,0,3],
[4,0,0,8,0,3,0,0,1],
[7,0,0,0,2,0,0,0,6],
[0,6,0,0,0,0,2,8,0],
[0,0,0,4,1,9,0,0,5],
[0,0,0,0,8,0,0,7,9]]
array=np.array(array)
b,l,old,result,count={1,2,3,4,5,6,7,8,9},[],[],[],[0]
for i in range(0,9):
for j in range(0,9):
if array[i,j]==0:
l.append((i,j))
sd(array,0)
print(result)
上一篇:python-生僻字转拼音
下一篇:大话python变量