Showing
1 changed file
with
78 additions
and
0 deletions
Picnic.cpp
0 → 100644
1 | +#include<iostream> | ||
2 | + | ||
3 | +using namespace std; | ||
4 | + | ||
5 | +int result; | ||
6 | +int N, M; | ||
7 | +bool areFriends[10][10]; | ||
8 | +bool havePair[10]; | ||
9 | + | ||
10 | +void counting(int n) | ||
11 | +{ | ||
12 | + bool finished = true; | ||
13 | + int first = -1; | ||
14 | + for (int i = 0;i < N;i++) | ||
15 | + { | ||
16 | + if (!havePair[i]) | ||
17 | + { | ||
18 | + finished = false; | ||
19 | + first = i; | ||
20 | + break; | ||
21 | + } | ||
22 | + } | ||
23 | + | ||
24 | + if (finished) | ||
25 | + { | ||
26 | + result += 1; | ||
27 | + return; | ||
28 | + } | ||
29 | + | ||
30 | + for (int j = first + 1;j < N;j++) | ||
31 | + { | ||
32 | + if (!havePair[first] && !havePair[j] && areFriends[first][j]) | ||
33 | + { | ||
34 | + havePair[first] = true; | ||
35 | + havePair[j] = true; | ||
36 | + counting(n+1); | ||
37 | + havePair[first] = false; | ||
38 | + havePair[j] = false; | ||
39 | + } | ||
40 | + } | ||
41 | + | ||
42 | + return; | ||
43 | +} | ||
44 | + | ||
45 | +int main() | ||
46 | +{ | ||
47 | + int test; | ||
48 | + cin >> test; | ||
49 | + | ||
50 | + for (int t = 1;t <= test;t++) | ||
51 | + { | ||
52 | + result = 0; | ||
53 | + for (int i = 0;i < 10;i++) | ||
54 | + { | ||
55 | + havePair[i] = false; | ||
56 | + for (int j = 0;j < 10;j++) | ||
57 | + { | ||
58 | + areFriends[i][j] = false; | ||
59 | + } | ||
60 | + } | ||
61 | + | ||
62 | + cin >> N >> M; | ||
63 | + | ||
64 | + for (int i = 0;i < M;i++) | ||
65 | + { | ||
66 | + int a, b; | ||
67 | + cin >> a >> b; | ||
68 | + areFriends[a][b] = true; | ||
69 | + areFriends[b][a] = true; | ||
70 | + } | ||
71 | + | ||
72 | + counting(0); | ||
73 | + | ||
74 | + cout << result << endl; | ||
75 | + } | ||
76 | + | ||
77 | + return 0; | ||
78 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment