-
Notifications
You must be signed in to change notification settings - Fork 0
/
picnic.cpp
57 lines (51 loc) · 1.02 KB
/
picnic.cpp
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include<iostream>
using namespace std;
bool pairFriends[10][10];
int n;
bool check[10] = {};
int countPair() {
int firstFree = -1;
for (int i = 0; i < n; i++) {
if (check[i] == false) {
firstFree = i;
break;
}
}
//기저사례 -> 짝을 다 찾은 경우는 종료
if (firstFree == -1) return 1;
int ret = 0;
for (int i = firstFree + 1; i < n; i++) {
if (!check[i] && pairFriends[firstFree][i]) {
check[i] = true;
check[firstFree] = true;
ret += countPair();
check[i] = false;
check[firstFree] = false;
}
}
return ret;
}
int main() {
int c, m; // 케이스 수, 학생수, 쌍의 수
cin >> c;
while (c--) {
cin >> n >> m;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
pairFriends[i][j] = false;
}
check[i] = false;
}
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
pairFriends[x][y] = true;
pairFriends[y][x] = true;
}
//함수 호출
int ret = countPair();
cout << ret << endl;
}
// cin >> n;
return 0;
}