Pagini recente » Cod sursa (job #1710380) | Cod sursa (job #1736383) | Cod sursa (job #828837) | Cod sursa (job #1665909) | Cod sursa (job #1514729)
#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;
}