Pagini recente » Cod sursa (job #1670062) | Cod sursa (job #1821505) | Cod sursa (job #1422961) | Cod sursa (job #2423132) | Cod sursa (job #2939166)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin("nr.in");
ofstream fout("nr.out");
int n,ap[20],st[20];
void Back(int k)
{
for(int x=1;x<=n;x++)
{
st[k]=x;
if(!ap[x] && !(k>1 && x<st[k-1]))
{
ap[x]=1;
for(int j=1;j<=k;j++)
cout << st[j] << " ";
cout << "\n";
Back(k+1);
ap[x]=0;
}
}
}
int main()
{
cin >> n;
Back(1);
return 0;
}