我犹豫应该使用以下两种数据结构中的哪一种来表示数独板,以便通过使用裸单和隐藏单技术来解决它。
1.
//using bool array to store candidates of a cell.
int[,] board = new int[9,9];
bool[,] isFixed = new bool[9,9]; // determine cell is fixed.
bool[,,] candidates = new bool[9,9,9];
这样,我们可以通过检查candidates[row, col, n]
是真还是假来检查单元格 (row,col) 是否包含候选 n
2.
int[,] board = new int[9,9];
bool[,] isFixed = new bool[9,9]; // determine cell is fixed.
bool[,] row = new bool[9,9]; //row(1,2) = true means number 2 was already appear (is solved or fixed) in 1st row
bool[,] col = new bool[9,9]; //col(1,2) = true means number 2 was already appear (is solved or fixed) in 1st col
bool[,] square3x3 = new bool[9,9]; //square3x3 (1,2) = true means number 2 was already appear (is solved or fixed) in 1st square3x3
这样,我们可以通过检查表达式row[r, n] && col[c, n] && square3x3[r/3 * 3 + c/3, n]
是真还是假来检查单元格 (r,c) 是否包含候选 n
当某个单元格用数字 n 求解时,在第一种方式中,我们必须更新某个单元格的 row, col, square3x3 中所有 3x9 单元格的候选者,而在第二种方式中,我们只设置 row[,n] , col [,n] 和 square3x3[,n] 为真。
但我不确定哪种方式适合和有效地找到裸单和隐藏单。
任何人都可以建议我找到隐藏单的算法吗?
帮帮我,谢谢!