Pagini recente » Cod sursa (job #1556036) | Cod sursa (job #1557484) | Cod sursa (job #509553) | Cod sursa (job #3314395) | Cod sursa (job #3304686)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("damesah.in");
ofstream fout("damesah.out");
constexpr int NMAX = 13;
int a[NMAX + 1];
int main() {
int n;
fin >> n;
for (int i = 1; i <= n; i++) {
a[i] = i;
}
long long ans = 0;
bool first = true;
do {
bool ok = true;
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (abs(i - j) == abs(a[i] - a[j]))
ok = false;
}
}
ans += ok;
if (ok && first) {
first = false;
for (int i = 1; i <= n; i++) {
fout << a[i] << ' ';
}
fout << '\n';
}
} while (next_permutation(a + 1, a + n + 1));
fout << ans;
}