Pagini recente » Profil altcontnou | Cod sursa (job #173266) | Cod sursa (job #3221485) | Cod sursa (job #239726) | Cod sursa (job #1876409)
#include <bits/stdc++.h>
using namespace std;
const int N_MAX = 17;
int n, m, solution;
int mat[N_MAX][N_MAX], st[N_MAX];
void read() {
ifstream fin("flip.in");
fin >> n >> m;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
fin >> mat[i][j];
}
}
fin.close();
}
void write() {
ofstream fout("flip.out");
int total_sum = 0;
for(int j = 1; j <= m; ++j){
int part_sum = 0;
for(int i = 1; i <= n; ++i) {
part_sum += (st[i]) ? mat[i][j] : -mat[i][j];
}
part_sum = max (part_sum, -part_sum);
total_sum += part_sum ;
}
solution = max (total_sum, solution);
fout << solution;
fout.close();
}
void backt(int level){
if (level == n + 1){
write();
return;
}
for (int i = 0; i < 2; ++i){
st[level] = i;
backt(level + 1);
}
}
int main() {
read();
backt(1);
return 0;
}