#include "pch.h" #include using namespace std; const int N = 8; int p[N]; int cnt = 0; void umisti(int s) { for (int i = 0; i < N; i++) { bool collision = false; for (int v = 1; v <= s && !collision; v++) { if (p[s - v] == i || p[s-v] == i-v || p[s-v] == i+v) collision = true; } if (!collision) { p[s] = i; if (s < N - 1) umisti(s + 1); else { for (int j = 0; j < N; j++) { cout << p[j] << " "; } cnt++; cout << " ... " << cnt << endl; } } } } int main() { for (int i = 0; i < N; i++) p[i] = -1; umisti(0); cout << "O.K." << endl; }