Cod sursa(job #1514729)
Utilizator | Alpaca Gedit gedica | Data | 31 octombrie 2015 15:29:12 |
---|---|---|---|
Problema | Generare de permutari | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.63 kb |
#include <fstream>
using namespace std;
ifstream fin("input.txt");
ofstream fout("output.txt");
const int nmax = 10;
int n, v[nmax+1], u[nmax+1];
void backtracking( int i ) {
if ( i <= n ) {
for ( int j = 1; j <= n; ++ j ) {
if( u[j]==0 )
{
v[i] = j;
u[j]= 1;
backtracking(i+1);
u[j]= 0;
}
}
} else {
for ( int j = 1; j <= n; ++ j ) {
fout << v[j] << " ";
}
fout << "\n";
}
}
int main( ) {
fin >> n;
backtracking(1);
return 0;
}