Skip to content

Instantly share code, notes, and snippets.

@VardanGrigoryan
Last active August 29, 2015 13:57
Show Gist options
  • Save VardanGrigoryan/9450697 to your computer and use it in GitHub Desktop.
Save VardanGrigoryan/9450697 to your computer and use it in GitHub Desktop.
Փոխարինել հետևյալ ռեկուրսիան իտերացւայով։
void backtrack(int* a, int k, int n)
{
if (k == n)
{
for(int i = 1; i <=k; ++i)
{
if (a[i] == true)
{
std::cout << i << " ";
}
}
std::cout << std::endl;
return;
}
bool c[2];
c[0] = false;
c[1] = true;
++k;
for(int i = 0; i < 2; ++i)
{
a[k] = c[i];
backtrack(a, k, n);
a[k] = INT_MAX;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment