-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path741.cpp
More file actions
73 lines (68 loc) · 1.16 KB
/
Copy path741.cpp
File metadata and controls
73 lines (68 loc) · 1.16 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include<iostream>
#include<cstring>
#include<string>
#include<bitset>
using namespace std;
int sample[101];
int len, n;
int ma;
void print() {
cout << "print:\n";
for (int i = 0; i < n; i++) {
bitset<32> t(sample[i]);
cout << t << endl;
}
}
void calc() {
int ans = 0;
int t[101];
memcpy(t, sample, sizeof(sample));
for (int i = 0; i < n; i++) {
int count = 0;
for (int j = 0; j < len; j++) {
count += (t[i] & 1);
t[i] = t[i] >> 1;
}
ans += count > (len - count) ? count : (len - count);
}
if (ans > ma) {
ma = ans;
}
}
void enu(int dep) {
if (dep == len) {
calc();
}
else {
for (int c = 0; c < 2; c++) {
if (c) {
enu(dep + 1);
}
else {
for (int i = 0; i < n; i++) {
sample[i] = sample[i] ^ (1 << dep);
}
enu(dep + 1);
for (int i = 0; i < n; i++) {
sample[i] = sample[i] ^ (1 << dep);
}
}
}
}
}
int main() {
while (cin >> n >> len) {
memset(sample, 0, sizeof(sample));
for (int i = 0; i < n; i++) {
string str;
cin >> str;
for (int j = 0; j < len; j++) {
sample[i] = (sample[i] << 1) + (str[j] == '1' ? 1 : 0);
}
}
ma = 0;
enu(0);
cout << ma << endl;
}
return 0;
}