#include bitsstdc++husing namespace std;int aans = 0;#define N 15int figN;char dpNN;int posx8 = -1-1011 1 0-1;int posy8 = 0 1110-1-1-1;bool INIT memsetdp sizeofdp; forint i = 1;i = a;i++
#include <bits/stdc++.h>
using namespace std;
int a,ans = 0;
#define N 15
int fig[N];
char dp[N][N];
int posx[8] = {-1,-1,0,1,1, 1, 0,-1};
int posy[8] = { 0, 1,1,1,0,-1,-1,-1};
bool INIT()
{
memset(dp,' ',sizeof(dp));
for(int i = 1;i <= a;i++)
{
dp[i][fig[i]] = 'Q';
}
for(int i = 1;i <= a;i++)
{
for(int j = 0;j < 8;j++)
{
int x = i,y = fig[i];
while(x >= 1 && y >= 1 && x <= a && y <= a)
{
x += posx[j];
y += posy[j];
if(dp[x][y] == 'Q')
{
return false;
}
dp[x][y] = '1';
}
}
}
return true;
}
void pos(int x)
{
if(x > a)
{
if(INIT())
{
ans++;
if(ans <= 3)
{
for(int i = 1;i <= a;i++) {cout << fig[i] << ' ';}
cout << endl;
}
}
return;
}
for(int i = 1;i <= a;i++)
{
if(!fig[i])
{
fig[i] = x;
pos(x + 1);
fig[i] = 0;
}
}
return;
}
int main()
{
cin >> a;
pos(1);
cout << ans;
return 0;
}
原文地址: https://www.cveoy.top/t/topic/i9Aa 著作权归作者所有。请勿转载和采集!