Pagini recente » Diferente pentru utilizator/lucib intre reviziile 2 si 1 | Diferente pentru problema/plimbare3 intre reviziile 6 si 5 | Cod sursa (job #3350160) | Cod sursa (job #3350158) | Cod sursa (job #3350159)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("permutari.in");
ofstream fout("permutari.out");
int solutie[20];
int visited[20];
void bkt(int pos,int n)
{
if(pos>n)
{
int cnt=0;
for(int i=1;i<=n;i++)
fout<<solutie[i]<<" ";
fout<<"\n";
return;
}
for(int val=1;val<=n;val++)
{
if(visited[val]==1) continue;
solutie[pos]=val;
visited[val]=1;
bkt(pos+1,n);
visited[val]=0;
}
}
int main()
{
int n;
fin>>n;
bkt(1,n);
return 0;
}