Several bug fixes

This commit is contained in:
krahets
2023-10-09 18:21:18 +08:00
parent fb552987f5
commit c37b7c807b
4 changed files with 21 additions and 18 deletions
+3 -2
View File
@@ -9,6 +9,7 @@
#define MAX_N 100
#define MAX_RES 1000
/* 放置结果 */
struct result {
char ***data;
int size;
@@ -17,8 +18,8 @@ struct result {
typedef struct result Result;
/* 回溯算法:N 皇后 */
void backtrack(int row, int n, char state[MAX_N][MAX_N], Result *res, bool cols[MAX_N], bool diags1[2 * MAX_N - 1],
bool diags2[2 * MAX_N - 1]) {
void backtrack(int row, int n, char state[MAX_N][MAX_N], Result *res,
bool cols[MAX_N], bool diags1[2 * MAX_N - 1], bool diags2[2 * MAX_N - 1]) {
// 当放置完所有行时,记录解
if (row == n) {
res->data[res->size] = (char **)malloc(sizeof(char *) * n);