题目内容
补充下列程序(数独):board = [[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]]def checkBoard(i,j,num):for t in range(9):if t!=j and board[i][t] == num:return Falseif t!= i and board[t][j] == num:return Falsefor t in range(i-i%3, 3+i-i%3):for s in range(j-j%3, 3+j-j%3):if t!=i and s!=j and board[t][s] ==num:return Falsereturn Trueres = []import copydef helper(index):if index==:solution= copy.deepcopy(board)res.append(solution)i =j =if :for num in range(1,10):board[i][j] = numif checkBoard(i,j,num):helper(index+1)else:helper(index+1)
查看答案
搜索结果不匹配?点我反馈
更多问题