Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool check(int board[8][8], int row, int j, int n) {
- for (int i = 0; i < n; i++) {
- if (board[row][i] == 1) {
- return false;
- }
- }
- for (int i = 0; i < n; i++) {
- if ((board[i][j]) == 1) {
- return false;
- }
- }
- for (int i = 1; i >= 0; i++) {
- if (j - i < 0) {
- break;
- }
- if (board[row - i][j - i] == 1) {
- return false;
- }
- }
- for (int i = 1; i >= 0; i++) {
- if (j - i < 0) {
- break;
- }
- if (board[row + i][j - i] == 1) {
- return false;
- }
- }
- return true;
- }
- int put(int board[8][8], int column, int count, int n) {
- if (column == n) {
- count++;
- }
- else {
- for (int i = 0; i < n; i++) {
- board[i][column] = 1;
- if (check(board, i, column, n)) {
- put(board, column + 1, count, n);
- }
- }
- }
- return count;
- }
- int task16() { //Ферзи
- int n, count = 0;
- cin >> n;
- int board[8][8];
- cout << put(board, 0, count, n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement