Write an algorithm to print all ways of arranging eight queens on a chess board so that none of them share the same row, column or diagonal.
#include <iostream>
using namespace std;
int n=8;
int tot=0;
int col[8];
void dfs(int cur)
{
if(cur==n)
tot++;//or print board
else for(int i=0; i<n; i++)
{
int ok=1;
col[cur]=i;
for(int j=0; j<cur; j++)
if(col[cur]==col[j] || cur-col[cur]== j-col[j] || cur+col[cur]==j+col[j])
{
ok=0;
break;
}
if(ok)
dfs(cur+1);
}
}
int main()
{
dfs(0);
cout << tot << endl;
return 0;
}