Pagini recente » Rating mce mec ecm (pheon23) | Rating Mihai Alex Ionescu (mika17) | Rating Dragos Gabriel Matu (Dragos_Matu) | Rating UNIBUC Harsan Bicsi Baltatu (echipa_BoSSilor) | Cod sursa (job #1582069)
#include<fstream>
#define NMAX 9
using namespace std;
FILE*in;
ofstream out("permutari.out");
int n;
int SOL[NMAX];
void read()
{
in=fopen("permutari.in", "r");
fscanf(in, "%d", &n);
}
void initializ(int number_k)
{
SOL[number_k]=0;
}
bool exist(int number_k)
{
if (SOL[number_k] < n)
return true;
return false;
}
bool condition(int number_k)
{
for (int i=1; i<number_k; i++)
if (SOL[i] == SOL[number_k])
return false;
return true;
}
bool solution(int number_k)
{
if (number_k == n)
return true;
return false;
}
void show()
{
for (int i=1; i<=n; i++)
out<<SOL[i]<<" ";
out<<'\n';
}
void BKT(int k)
{
while (k > 0)
{
if (exist(k))
{
SOL[k]++;
if (condition(k))
{
if (solution(k))
show();
else
{
k++;
initializ(k);
}
}
}
else
k--;
}
}
int main()
{
read();
BKT(1);
return 0;
}