-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14889.cpp
More file actions
58 lines (52 loc) · 1.66 KB
/
14889.cpp
File metadata and controls
58 lines (52 loc) · 1.66 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 <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
int min_score = 2147483647;
cin >> n;
vector<int> temp(n, 0);
for (int i = n / 2; i < n; i++) {
temp[i] = 1;
}
vector<vector<int> > arr(n + 1, vector<int>(n + 1, 0));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
int x;
cin >> x;
arr[min(i, j)][max(i, j)] += x;
}
}
do {
vector<int> team1;
vector<int> team2;
vector<int> team_temp(n / 2, 1);
int team1_now_score = 0;
int team2_now_score = 0;
team_temp[0] = 0;
team_temp[1] = 0;
for (int i = 0; i < n; i++) {
if (temp[i] == 0) team1.push_back(i + 1);
else team2.push_back(i + 1);
}
do {
vector<int> team1_add_score;
vector<int> team2_add_score;
for (int i = 0; i < n / 2; i++) {
if (team_temp[i] == 0) {
team1_add_score.push_back(team1[i]);
team2_add_score.push_back(team2[i]);
}
}
team1_now_score += arr[team1_add_score[0]][team1_add_score[1]];
team2_now_score += arr[team2_add_score[0]][team2_add_score[1]];
} while (next_permutation(team_temp.begin(), team_temp.end()));
//cout << team1_now_score << " " << team2_now_score << "\n";
min_score = min(min_score, abs(team1_now_score - team2_now_score));
} while (next_permutation(temp.begin(), temp.end()));
cout << min_score << "\n";
return 0;
}