Pagini recente » Cod sursa (job #997298) | Cod sursa (job #675361) | Cod sursa (job #2192705) | Cod sursa (job #3233001) | Cod sursa (job #2191993)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("permutari.in");
ofstream fout("permutari.out");
int n;
bitset<10>ap;
int perm[10];
void bkk(int pos)
{
for(int i=1;i<=n;i++)
{
if(ap[i]==0)
{
ap[i]=1;
if(pos<n)
{
perm[pos]=i;
bkk(pos+1);
}
else
{
for(int j=1;j<=n-1;j++)
fout<<perm[j]<<" ";
fout<<i<<"\n";
}
ap[i]=0;
}
}
}
int main()
{
fin>>n;
bkk(1);
return 0;
}