Advertisement
OIQ

rayon4_2

OIQ
Nov 22nd, 2019
164
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. vector <bool> used;
  8. vector <int> stack;
  9. int t;
  10.  
  11. void get_perm(int pos, int left) {
  12.     if (t == 0)
  13.         return;
  14.  
  15.     if (left == 0) {
  16.         for (int i = 1; i < stack.size(); i++)
  17.             printf("%d ", stack[i]);
  18.         printf("\n");
  19.         t--;
  20.         return;
  21.     }
  22.  
  23.     for (int i = 1; i < used.size(); i++)
  24.         if (!used[i] && pos != i) {
  25.             used[i] = true;
  26.             stack[pos] = i;
  27.             get_perm(pos + 1, left - 1);
  28.             used[i] = false;
  29.         }
  30.  
  31. }
  32.  
  33. int main() {
  34.     int n;
  35.  
  36.     cin >> n >> t;
  37.  
  38.     used.resize(n + 1, false);
  39.     stack.resize(n + 1);
  40.  
  41.     get_perm(1, n);
  42.  
  43. }
Advertisement
RAW Paste Data Copied
Advertisement