lugou P1219
作者:
jy9
,
2024-12-10 21:46:32
,
所有人可见
,
阅读 2
#include <iostream>
using namespace std;
const int N = 15;
int n;
int cnt;
bool col[N], djx[N+N], fdjx[N+N];
int ans[N];
void dfs(int u){
if(u == n + 1){
cnt++;
if(cnt <= 3){
for (int i = 1; i <= n; i ++ ){
cout << ans[i] <<' ';
}
cout << endl;
}
return;
}
for (int i = 1; i <= n; i ++ ){
if(col[i] || djx[u-i+n] || fdjx[i+u]) continue;
col[i] = djx[u-i+n] = fdjx[i+u] = 1;
ans[u] = i;
dfs(u+1);
col[i] = djx[u-i+n] = fdjx[i+u] = 0;
}
}
int main()
{
cin >> n;
dfs(1);
cout << cnt;
return 0;
}