ChoDog

D: rek

Nov 22nd, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. int n, t;
  8.  
  9. FILE* out = fopen("output.txt", "w");
  10.  
  11. void rek(int pos, vector<int> &vec, vector<bool> &isb){
  12.     if(t == 0) return;
  13.     if(pos == n){
  14.         t--;
  15.         for(int i = 0; i < n; i++){
  16.             fprintf(out,"%d%c", vec[i], ' ');
  17.         }
  18.         fprintf(out,"\n");
  19.         return;
  20.     }
  21.  
  22.     for(int i = 1; i <= n; i++){
  23.         if(pos + 1 == i || isb[i])
  24.             continue;
  25.         vec[pos] = i;
  26.         isb[i] = true;
  27.         rek(pos +1, vec, isb);
  28.         isb[i] = false;
  29.     }
  30.  
  31.  
  32. }
  33.  
  34. int main(){
  35.    
  36.     scanf("%d%d", &n, &t);
  37.     vector<int> vec(n);
  38.     vector<bool> isb(n+1, false);
  39.     rek(0, vec, isb);
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment