void Afis()
{
for (int j = 1; j <= n; j++)
cout << x[j] << " ";
cout << endl;
}

bool OK(int k) {
for (int i = 1; i < k; ++i)
if (x[k] == x[i])
return false;
return true;
}



void back(int k) {
for (int i = 1; i <= n; ++i)
{
x[k] = i;
if (OK(k))
if (k==n)
Afis();
else
back(k + 1);
}
}

//--------------------------------------------------------------
void ofApp::setup(){
cin >> n;
back(1);
}

No comment

Leave a Reply

Your email address will not be published. Required fields are marked *