Пример #1
0
// driver program to test above function
int main()
{
    solveNQ();
 
    getchar();
    return 0;
}
Пример #2
0
 void solveNQ(int n, int irow, vector<int> &col, int &totSol) {
     if(irow == n) {
         totSol++;
         return;
     }
     
     for(int icol = 0; icol < n; ++icol) {
         if(validPos(col, irow, icol)) {
             col.push_back(icol);
             solveNQ(n, irow + 1, col, totSol);
             col.pop_back();
         }
     }
 }
Пример #3
0
 int totalNQueens(int n) {
     vector<int> col;
     int totSol = 0;
     solveNQ(n, 0, col, totSol);
     return totSol;
 }
Пример #4
0
int main(){
    solveNQ();
}