Cod sursa(job #3195401)
Utilizator | Lavrente Simion Simifil | Data | 20 ianuarie 2024 18:14:29 |
---|---|---|---|
Problema | Generare de permutari | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.5 kb |
// Source: https://usaco.guide/general/io
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("permutari.in");
ofstream g("permutari.out");
const int maxn = 10;
int n;
int v[maxn], fr[maxn];
void back( int poz )
{
if( poz == n + 1 )
{
for( int i = 1; i <= n; ++i )
g << v[i] << ' ';
g << '\n';
}
else
{
for( int i = 1; i <= n; ++i )
{
if( fr[i] == 0 )
{
fr[i] = 1;
v[poz] = i;
back( poz + 1 );
fr[i] = 0;
}
}
}
}
int main()
{
f >> n;
back( 1 );
}