if (col == N) { for (int i = 0; i < N; i++) table[count][i] = ans[i]; count++; } else for (int x = 0; x < N; x++)//col 行的第 x 列 { int d1 = x + col, d2 = col - x + 7; if (!mx[x] && !s1[d1] && !s2[d2]) { mx[x] = s1[d1] = s2[d2] = true; ans[col] = x; build(col + 1); mx[x] = s1[d1] = s2[d2] = false; } }
return count; } intmain() { int kind = build(0), Case, map[N][N]; scanf("%d", &Case); while (Case--) { int i, j; for (i = 0; i < N; i++) for (j = 0; j < N; j++) scanf("%d", &map[i][j]);
int sum, max = 0; for (i = 0; i < kind; i++) { sum = 0; for (j = 0; j < N; j++) sum += map[j][table[i][j]]; if (sum > max) max = sum; }