SHARE
TWEET

Untitled

a guest Aug 25th, 2019 63 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.        
  16.         if(x >= 1) {
  17.           if(result[x] < result[x-1]) continue;
  18.         }
  19.         check[i] = true;
  20.        
  21.         DFS(x+1);
  22.        
  23.         check[i] = false;
  24.         result[x] = 0;
  25.       }
  26.     }
  27.   }
  28. }
  29.  
  30. int main() {
  31.   scanf("%d %d", &n, &m);
  32.  
  33.   DFS(0);
  34.  
  35.   return 0;
  36. }
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