-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuxuhulvoting.cc
More file actions
58 lines (43 loc) · 1.48 KB
/
uxuhulvoting.cc
File metadata and controls
58 lines (43 loc) · 1.48 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
#include <cstdio>
#include <vector>
#include <algorithm>
int memo[101][8];
int pref[100][8]; // Preferences.
int n_priests;
void dump_state(int state) {
char l = state & 0b100 ? 'Y' : 'N';
char m = state & 0b010 ? 'Y' : 'N';
char r = state & 0b001 ? 'Y' : 'N';
printf("%c%c%c\n", l, m, r);
}
int solve(int priest, int state) {
if (priest >= n_priests) return state;
if (memo[priest][state] != -1) return memo[priest][state];
int exit_state = std::min<int>(
{solve(priest + 1, state ^ 1), solve(priest + 1, state ^ 2), solve(priest + 1, state ^ 4)},
[priest](int lhs, int rhs) {
return pref[priest][lhs] < pref[priest][rhs];
});
//printf("best exit_state: "); dump_state(exit_state);
memo[priest][state] = exit_state;
return exit_state;
}
int main() {
int n_votes; scanf("%d", &n_votes);
while (n_votes--) {
// Prepare memo.
for (int i = 0; i < 101; i++) {
for (int j = 0; j < 8; j++)
memo[i][j] = -1;
}
scanf("%d", &n_priests);
for (int p = 0; p < n_priests; p++) {
scanf("%d %d %d %d %d %d %d %d",
&pref[p][0], &pref[p][1], &pref[p][2], &pref[p][3],
&pref[p][4], &pref[p][5], &pref[p][6], &pref[p][7]);
//printf("first = %d, last = %d\n", p.pref.front(), p.pref.back());
}
int result = solve(0, 0);
dump_state(result);
}
}