Cod sursa(job #3213701)
Utilizator | TanasucaGeorgeAlexandru TanasucaGeorgeAlexandru | Data | 13 martie 2024 12:59:39 |
---|---|---|---|
Problema | Generare de permutari | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.55 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("permutari.in");
ofstream fout("permutari.out");
int st[10];
bitset <10> v;
int n;
void Fish(int n){
for(int i=1;i<=n;i++) fout << st[i] << " ";
fout << "\n";
}
void Back(int top){
if(top==n+1){
Fish(top-1);
return;
}
for(int i=1;i<=n;i++){
if(!v[i]){
v[i]=1;
st[top]=i;
Back(top+1);
v[i]=0;
}
}
}
int main()
{
fin >> n;
Back(1);
return 0;
}