Pagini recente » Cod sursa (job #1387043) | Cod sursa (job #3293664) | Cod sursa (job #2081556) | Cod sursa (job #1423876) | Cod sursa (job #1518942)
#include <cstdio>
#define max(a,b) (a > b ? a : b)
using namespace std;
const int nmx = 20;
const int inf = 0x3f3f3f3f;
int n,m,mat[nmx][nmx],c[nmx],r = -inf;
void input(){
scanf("%d %d", &n, &m);
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= m; ++j)
scanf("%d", &mat[i][j]);
}
void calc(){
int total = 0;
for(int i = 1; i <= n; ++i){
int sum = 0;
for(int j = 1; j <= m; ++j)
sum += mat[i][j] * c[j];
total += max(sum,-sum);
}
r = max(r,total);
}
void backtracking(int pos){
if(pos == m + 1){
calc();
return;
}
c[pos] = 1;
backtracking(pos+1);
c[pos] = -1;
backtracking(pos+1);
return;
}
int main(){
freopen("flip.in", "r", stdin);
freopen("flip.out", "w", stdout);
input();
backtracking(0);
printf("%d\n", r);
return 0;
}