n皇后
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
#include<string.h>
#include<sstream>
using namespace std;
const int maxn=1e3+10;
int n,m;
int rec[maxn];
int cnt=0;
int dfs( int row)
{
if(row==n)
{
cnt++;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(j==rec[i])cout<<1<<" ";
else cout<<"0"<<" ";
}
cout<<endl;
}
return 1;
}
for(int col=0;col<n;col++)
{
int ok=1;
for(int i=0;i<row;i++){
if(rec[i]==col||i+rec[i]==row+col||row-col==i-rec[i]){
ok=0;
break;
}
}
if(ok)
{
rec[row]=col;//row等于列
dfs(row+1);
}
}}
int main()
{
n=4;
dfs(0);
cout<<cnt;
}