Cod sursa(job #2705480)

Utilizator BogdanBurescuBogdan Burescu BogdanBurescu Data 12 februarie 2021 17:15:21
Problema Generare de permutari Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.4 kb
#include<iostream>

using namespace std;

int a[20], n, viz[20];

void PrintSol()
{
	int i;
	for (i = 1; i <= n; i++)
		cout << a[i] << " ";
	cout << "\n";
}

void Back(int top)
{
	int i;
	if (top==n+1) PrintSol();
	else
        for (i=1;i<=n;i++)
		if (!viz[i])
		{
			viz[i]=1;
			a[top]=i;
			Back(top+1);
			viz[i]=0;
		}
}

int main()
{
	cin>>n;
	Back(1);
	return 0 ;
}