Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <vector>
- using namespace std;
- int n, t;
- FILE* out = fopen("output.txt", "w");
- void rek(int pos, vector<int> &vec, vector<bool> &isb){
- if(t == 0) return;
- if(pos == n){
- t--;
- for(int i = 0; i < n; i++){
- fprintf(out,"%d%c", vec[i], ' ');
- }
- fprintf(out,"\n");
- return;
- }
- for(int i = 1; i <= n; i++){
- if(pos + 1 == i || isb[i])
- continue;
- vec[pos] = i;
- isb[i] = true;
- rek(pos +1, vec, isb);
- isb[i] = false;
- }
- }
- int main(){
- scanf("%d%d", &n, &t);
- vector<int> vec(n);
- vector<bool> isb(n+1, false);
- rek(0, vec, isb);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment