Pagini recente » Cod sursa (job #1983795) | Cod sursa (job #3192480) | Cod sursa (job #1071232) | Cod sursa (job #1617969) | Cod sursa (job #1253734)
#include <iostream>
#include <cstdio>
using namespace std;
int P[100],n;
bool V[100];
void bk(int l)
{ int i;
if (l<=n)
for ( i=1;i<=n;i++)
{
if (V[i]==false)
{
V[i]=true;
P[l]=i;
bk(l+1);
P[l]=0;
V[i]=false;
}
}
else
{
for ( i=1;i<=n;i++) printf("%d ",P[i]);
printf("\n");
}
}
int main()
{
freopen("permutari.in","r",stdin);
freopen("permutari.out","w",stdout);
scanf("%d",&n);
bk(1);
}