-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuva10264.cpp
More file actions
52 lines (42 loc) · 1.05 KB
/
uva10264.cpp
File metadata and controls
52 lines (42 loc) · 1.05 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
#include<iostream>
#include<bitset>
#include<string>
using namespace std;
int weight[1<<16];
int potency[1<<16];
int main() {
string s;
while(true) {
getline(cin,s);
if (s.length() == 0) {
break;
}
int m = stoi(s);
int n = 1 << m;
for(int i = 0; i < n; i++) {
getline(cin,s);
weight[i] = stoi(s);
}
for (unsigned long long i = 0; i < n; i++) {
potency[i] = 0;
bitset<16> b(i);
for(unsigned long long j = 0; j < m; j++) {
b.flip(j);
int ind = b.to_ulong();
potency[i] += weight[ind];
b.flip(j);
}
}
int ans = 0;
for (int i = 0; i < n; i++) {
bitset<16> b(i);
for(int j = 0; j < m; j++) {
b.flip(j);
int ind = b.to_ulong();
ans = max(ans, potency[i] + potency[ind]);
b.flip(j);
}
}
cout << ans << endl;
}
}