-
Notifications
You must be signed in to change notification settings - Fork 0
/
피크닉
114 lines (100 loc) · 2.42 KB
/
피크닉
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int t, c, n, m;
bool check[45];
void count_pair(int selected, int index, int k, vector<pair<int, int>>& student){
if(selected == k){
bool student_check[10];
fill(student_check, student_check+10, false);
for(int i = 0 ; i<m ; i++){
if(check[i]){
int a = student[i].first;
int b = student[i].second;
if(student_check[a] || student_check[b]) return;
student_check[a] = true;
student_check[b] = true;
}
}
c+=1;
return;
}
if(index>=m) return;
check[index] = true;
count_pair(selected+1, index+1, k, student);
check[index] = false;
count_pair(selected, index+1, k, student);
}
int main() {
ios_base :: sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> t;
while(t--){
vector <pair<int, int>> student;
c=0;
cin >> n >> m;
for(int i = 0 ; i<m ; i++){
int a, b;
cin >> a >> b;
student.push_back(make_pair(a, b));
}
count_pair(0, 0, n/2, student);
cout << c <<'\n';
}
return 0;
}
/*
#include <iostream>
#include <string>
using namespace std;
int t, n, m;
bool friends[10][10];
int find_pair(bool taken[10]){
int ret = 0;
int first = -1;
//아직 짝이 없는 친구중 가장 낮은 친구 찾기
for(int i = 0 ; i<n ; i++){
if(!taken[i]){
first = i;
break;
}
}
//모두 짝이 있을 경우
if(first == -1){
return 1;
}
for(int i = first+1 ; i<n ; i++){
if(!taken[i] && friends[first][i]){
taken[first] = taken[i] = true;
ret += find_pair(taken);
taken[first] = taken[i] = false;
}
}
return ret;
}
void init(){
for(int i = 0 ; i<n ; i++)
for(int j = 0 ; j<n ; j++)
friends[i][j] = false;
return;
}
int main() {
cin >> t;
while(t--){
cin >> n >> m;
init();
for(int i = 0 ; i<m ; i++){
int a, b;
cin >> a >> b;
friends[a][b] = true;
friends[b][a] = true;
}
bool taken[10] ={false, };
int total_pair = find_pair(taken);
cout << total_pair << '\n';
}
return 0;
}
*/