Pagini recente » Cod sursa (job #889114) | Cod sursa (job #973747) | Cod sursa (job #250085) | Cod sursa (job #2776937) | Cod sursa (job #1599741)
// Day6V2.cpp : Defines the entry point for the console application.
//
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("submultimi.in");
ofstream g("submultimi.out");
int st[20], n, m = 1;
void afisare() {
for (int i = 1; i <= m; ++i)
cout << st[i] << " ";
cout << "\n";
}
int valid(int k) {
for (int i = 1; i < k; ++i) {
if (st[i] == st[k] || st[k] < st[k - 1])
return 0;
}
return 1;
}
void BK(int k) {
for (int i = 1; i <= n; ++i) {
st[k] = i;
if (valid(k))
if (k == m)
afisare();
else
BK(k + 1);
}
}
int main()
{
f >> n;
while (m <= n) {
BK(1);
++m;
}
return 0;
}