Advertisement
Guest User

Untitled

a guest
Aug 25th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int n, m, result[10];
  4. bool check[10];
  5.  
  6. void DFS(int x) {
  7. if(x == m) {
  8. for(int i=0;i<x;i++) printf("%d ", result[i]);
  9. printf("\n");
  10. }
  11. else {
  12. for(int i=1;i<=n;i++) {
  13. if(!check[i]) {
  14. result[x] = i;
  15. check[i] = true;
  16.  
  17. DFS(x+1);
  18.  
  19. check[i] = false;
  20. result[x] = 0;
  21. }
  22. }
  23. }
  24. }
  25.  
  26. int main() {
  27. scanf("%d %d", &n, &m);
  28.  
  29. DFS(0);
  30.  
  31. return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement