-
Notifications
You must be signed in to change notification settings - Fork 0
/
domino.cpp
68 lines (53 loc) · 1.08 KB
/
domino.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
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int N;
struct Tessera {
int s,d;
};
vector<Tessera> t;
vector<Tessera> r;
vector<bool> used;
vector<Tessera> permutazione;
int length=0;
void findPermutation(int pos) {
if (pos > length) {
length=pos;
}
for (int i=0; i<N; i++) {
if (pos==0 || (permutazione[pos-1].d == t[i].s && used[i]==false)) {
permutazione[pos]=t[i];
used[i]=true;
findPermutation(pos+1);
used[i]=false;
}
if (pos==0 || (permutazione[pos-1].d == r[i].s && used[i]==false)) {
permutazione[pos]=r[i];
used[i]=true;
findPermutation(pos+1);
used[i]=false;
}
}
}
int main() {
t.resize(10);
r.resize(10);
used.resize(10);
permutazione.resize(10);
ifstream in("input.txt");
ofstream out("output.txt");
in>>N;
for (int i=0; i<N; i++) {
in >> t[i].s;
in >> t[i].d;
r[i].s = t[i].d;
r[i].d = t[i].s;
}
for (int i=0; i<N; i++) {
used[i] = false;
}
findPermutation(0);
cout << length;
return 0;
}