Pagini recente » Cod sursa (job #2951335) | Cod sursa (job #1461962) | Cod sursa (job #1944418) | Cod sursa (job #1552901) | Cod sursa (job #2241612)
#include <fstream>
#include <iostream>
std::ifstream fin ("submultimi.in");
std::ofstream fout ("submultimi.out");
const int MaxN = 17;
int n, a[MaxN];
void Write(int poz);
bool Ok(int pos);
void Back_Track(int pos);
int main ()
{
fin >> n;
Back_Track(1);
return 0;
}
void Write(int pos)
{
for (int i = 1; i <= pos; ++i)
fout << a[i] << ' ';
fout << '\n';
}
bool Ok(int pos)
{
if(pos > n)
return false;
for (int i = 1; i <= pos - 1; ++i)
if (a[pos] == a[i])
return false;
return true;
}
void Back_Track(int pos)
{
for (int i = 1; i <= n; ++i)
{
a[pos] = i;
if (Ok(pos))
{
Write(pos);
Back_Track(pos + 1);
}
}
}