-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path15649.cpp
More file actions
43 lines (39 loc) · 685 Bytes
/
15649.cpp
File metadata and controls
43 lines (39 loc) · 685 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdio.h>
#include <string>
#include <string.h>
#include <vector>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#define MAX 9
#pragma warning(disable:4996)
#define _CRT_SECURE_NO_WARNINGS
using namespace std;
int N, M;
bool visit[MAX];
vector<int> V;
void DFS(int cnt) {
if (cnt == M) {
for (int i = 0; i < V.size(); i++) {
cout << V[i] << " ";
}
cout << "\n";
return;
}
for (int i = 1; i <= N; i++) {
if (visit[i] == true)continue;
visit[i] = true;
V.push_back(i);
DFS(cnt + 1);
visit[i] = false;
V.pop_back();
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> N >> M;
DFS(0);
return 0;
}