Advertisement
deushiro

municip

Nov 26th, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. vector<int> a;
  6. vector<bool> flag;
  7. int n, t;
  8.  
  9. void rec(int v){
  10.     if(t == 0){
  11.         return;
  12.     }
  13.     if(v == n){
  14.         for(int i = 0; i < a.size(); ++i){
  15.             cout << a[i] + 1 << " ";
  16.         }
  17.         cout << endl;
  18.         --t;
  19.     }
  20.     for(int i = 0; i < n; ++i){
  21.         if(i != v  && !flag[i]){
  22.             flag[i] = true;
  23.             a.push_back(i);
  24.             rec(v + 1);
  25.             flag[i] = false;
  26.             a.pop_back();
  27.         }
  28.     }
  29. }
  30.  
  31. int main() {
  32.     ios_base::sync_with_stdio(false);
  33.     cin.tie(0);
  34.     cout.tie(0);
  35.     cin >> n >> t;
  36.     flag.resize(n, false);
  37.     rec(0);
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement