You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
963 B
46 lines
963 B
#include<bits/stdc++.h>
|
|
using namespace std;
|
|
// 一行一行的枚举,先枚举第一行,然后枚举每一列,在枚举的列的时候对行进行深搜。
|
|
int n, cnt = 0, _map[10][10], vis[10][10];
|
|
|
|
bool check(int x, int y, int color) {
|
|
int i, j;
|
|
for (i = 1; i <= x; i++)
|
|
if (vis[i][y] == color) return false;
|
|
for (i = x, j = y; i > 0 && j > 0; i--, j--)
|
|
if (vis[i][j] == color) return false;
|
|
for (i = x, j = y; i > 0 && j <= n; i--, j++)
|
|
if (vis[i][j] == color) return false;
|
|
return true;
|
|
}
|
|
void dfs(int i) {
|
|
int j, k;
|
|
if (i > n) {
|
|
cnt++;
|
|
return;
|
|
}
|
|
for (j = 1; j <= n; j++) {
|
|
if (_map[i][j] == 1 && check(i, j, 1)) {
|
|
vis[i][j] = 1;
|
|
for (k = 1; k <= n; k++) {
|
|
if (j != k && _map[i][k] == 1 && check(i, k, -1)) {
|
|
vis[i][k] = -1;
|
|
dfs(i + 1);
|
|
vis[i][k] = 0;
|
|
}
|
|
}
|
|
vis[i][j] = 0;
|
|
}
|
|
}
|
|
}
|
|
int main() {
|
|
int i, j;
|
|
cin >> n;
|
|
for (i = 1; i <= n; i++)
|
|
for (j = 1; j <= n; j++)
|
|
cin >> _map[i][j];
|
|
dfs(1);
|
|
cout << cnt << endl;
|
|
return 0;
|
|
}
|