Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Created June 11, 2025 17:34
Show Gist options
  • Save thinkphp/a069698f8108842390273192c29d66f4 to your computer and use it in GitHub Desktop.
Save thinkphp/a069698f8108842390273192c29d66f4 to your computer and use it in GitHub Desktop.
bkt recursive perm
#include <stdio.h>
#define SIZE 100
int n,
sol[SIZE],
used[SIZE];
void perm(int level ) {
if(level == n + 1) {
for(int i = 1; i <= n; i++) {
printf("%d ", sol[i]);
}
printf("\n");
} else {
for(int i = 1; i <= n; ++i) {
if(!used[i]) {
sol[level] = i;
used[i] = 1;
perm(level+1);
used[i] = 0;
}
}
}
}
int main(int argc, char const *argv[]) {
printf("n=");
scanf("%d",&n);
perm(1);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment