====== Osm dam ===== #include using namespace std; const int N = 8; int a [N+1]; // a[0] nepouzivam int cnt = 0; void tisk () { cnt ++; if (1) { for (int s = 1; s <= N; s++) cout << a [s] << ' '; cout << endl; } if (0) { for (int r = 1; r <= N; r++) { for (int s = 1; s <= N; s++) if (a[s] == r) cout << "* "; else cout << ". "; cout << endl; } cout << endl; } } void umisti (int s) { for (int r = 1; r <= N; r++) { bool ok = true; for (int k = 1; k < s; k++) if (a[s-k] == r || a[s-k] == r-k || a[s-k] == r+k) ok = false; if (ok) { a [s] = r; // umisti damu v ramci sloupce 's' na radku 'r' if (s < N) umisti (s+1); else tisk (); } } } int main() { for (int i = 0; i <= N; i++) a [i] = 0; umisti (1); cout << "cnt = " << cnt << endl; }