Backtracking Recursiv



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);
}

Texte

In h declaram:

ofTrueTypeFont f;

In cpp scriem:

In start: f.load(“dogicapixelbold.ttf”, 30);

In draw: f.drawString(“scor: ” + ofToString(n), 700, 90);