我希望为我的Sudoku Solver优化我的回溯算法.
它现在做了什么:
递归求解器函数采用具有各种给定值的数独谜题.
我将遍历拼图中的所有空槽,寻找可能性最小的槽,并获取值列表.
从值列表中,我将通过将列表中的一个值放入插槽中来循环遍历它,并递归地求解它,直到填满整个网格.
对于一些难题,这种实现仍然需要非常长的时间,我希望进一步优化这一点.有没有人有任何想法我怎么能够进一步优化这个?
如果您有兴趣,这是我的Java代码.
public int[][] Solve(int[][] slots) {
// recursive solve v2 : optimization revision
int[] least = new int[3];
least[2] = Integer.MAX_VALUE;
PuzzleGenerator value_generator = new PuzzleGenerator();
LinkedList<Integer> least_values = null;
// 1: find a slot with the least possible solutions
// 2: recursively solve.
// 1 - scour through all slots.
int i = 0;
int j = 0;
while (i < 9) {
j = 0;
while (j < 9) {
if …Run Code Online (Sandbox Code Playgroud)