Pagini recente » Cod sursa (job #2853010) | Cod sursa (job #2635834) | Cod sursa (job #2525107) | Cod sursa (job #1408528) | Cod sursa (job #2537915)
#include <bits/stdc++.h>
using namespace std;
const int len = 2 << 10;
int arr[len], n;
ifstream fin("permutari.in");
ofstream fout("permutari.out");
bool check(int step) {
for (int i = 1; i < step; i++)
if (arr[i] == arr[step])
return false;
return true;
}
void bt(int step) {
if (step == n + 1) {
for (int i = 1; i <= n; i++)
fout << arr[i] << " ";
fout << "\n";
}
else {
for (int i = 1; i <= n; i++) {
arr[step] = i;
if (check(step))
bt(step + 1);
}
}
}
int main() {
fin >> n;
bt(0);
}