Sudoku solving algorithm C++

前端 未结 4 1685
没有蜡笔的小新
没有蜡笔的小新 2021-01-31 07:04

I\'m trying to make a Sudoku Solving program for a couple of days but I\'m stuck with the methods. I found this algorithm here but I don\'t really understand it:

4条回答
  •  闹比i
    闹比i (楼主)
    2021-01-31 07:12

    There is one very important modification to recursive algorithms: Use most constrained first approach. This means first to solve a cell with smallest number of possible candidates (when direct row/column/block conflicts are removed).

    Another modification is: Change the board in-place; do not copy it. In each recursive call you modify only one cell on the board, and that cell used to be empty. If that call doesn't end up in a solved board somewhere down the recursive call tree, just clear the cell again before returning - this returns the board into original state.

    You can find a very short and fast solution in C# on address: Sudoku Solver. It solves arbitrary sudoku board in about 100 steps only, all thanks to the most constrained first heuristic.

提交回复
热议问题