Advertisement
TwITe

Untitled

Jul 31st, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. bool check(int board[100][100], int row, int column, int n) {
  2.     for (int i = 0; i < column; i++) {
  3.         if (board[row][i] == 1) {
  4.             return false;
  5.         }
  6.     }
  7.     /*for (int i = n - 1; i > row; i++) {
  8.         if ((board[i][column]) == 1) {
  9.             return false;
  10.         }
  11.     }*/
  12.     for (int i = 1; i <= n; i++) {
  13.         if (column - i < 0) {
  14.             break;
  15.         }
  16.             if (board[row - i][column - i] == 1) {
  17.                 return false;
  18.             }
  19.     }
  20.     for (int i = 1; i <= n; i++) {
  21.         if (column - i < 0) {
  22.             break;
  23.         }
  24.         if (board[row + i][column - i] == 1) {
  25.             return false;
  26.         }
  27.     }
  28.     return true;
  29. }
  30.  
  31. void put(int board[100][100], int column, int count, int n) {
  32.     if (column >= n || column >= n - 1) {
  33.         count++;
  34.     }
  35.     for (int row = 0; row < n; row++) {
  36.         board[row][column] = 1;
  37.         if (check(board, row, column, n)) {
  38.             put(board, column + 1, count, n);
  39.         }
  40.         board[row][column] = 0;
  41.     }
  42. }
  43.  
  44. int task16() { //Ферзи
  45.     int n, count = 0;
  46.     cin >> n;
  47.     int board[100][100];
  48.     put(board, 0, count, n);
  49.     cout << count;
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement