Pagini recente » Cod sursa (job #196421) | Monitorul de evaluare | Cod sursa (job #2903366) | Cod sursa (job #880660) | Cod sursa (job #2099479)
#include <fstream>
using namespace std;
ifstream fin ("permutari.in");
ofstream fout ("permutari.out");
int Back(int k);
bool Verifpoz(int k);
void ReadSolution();
const int MaxN{50000};
int n, a[MaxN];
int main()
{
fin >> n;
Back(1);
fin.close();
fout.close();
return 0;
}
int Back(int k)
{
int i;
for (int i = 1; i <= n; ++i)
{
a[k] = i;
if (Verifpoz(k))
{
if (k == n)
ReadSolution();
else
Back(k + 1);
}
}
}
bool Verifpoz(int k)
{
for (int i = 1;i < k; ++i)
if (a[i] == a[k])
return false;
return true;
}
void ReadSolution()
{
for (int i = 1; i <= n; ++i)
fout << a[i] << ' ';
fout << '\n';
}