SHARE
TWEET

Untitled

a guest Aug 25th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top