Pagini recente » Cod sursa (job #940729) | Cod sursa (job #2417829) | Cod sursa (job #557980) | Cod sursa (job #2961824) | Cod sursa (job #61430)
Cod sursa(job #61430)
#include <cstdio>
#include <cstdlib>
int n, m;
int table[16][16];
int bitmask[16] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768};
int main() {
FILE * f = fopen("flip.in", "r");
fscanf(f, "%d %d", &n, &m);
for (int row = 0; row < n; row ++) {
for (int col = 0; col < m; col ++) {
fscanf(f, "%d", &table[row][col]);
}
}
fclose(f);
int best = 0;
for (int combination = 0; combination < (1 << n); combination ++) {
int sum = 0;
for (int col = 0; col < m; col ++) {
int col_sum = 0;
for (int row = 0; row < n; row ++) {
if ((combination & bitmask[row]) > 0) {
col_sum -= table[row][col];
} else {
col_sum += table[row][col];
}
}
sum += abs(col_sum);
}
best >?= sum;
}
f = fopen("flip.out", "w");
fprintf(f, "%d\n", best);
fclose(f);
return 0;
}