Pagini recente » Cod sursa (job #2350356) | Cod sursa (job #418596) | Cod sursa (job #215984) | Cod sursa (job #465550) | Cod sursa (job #2853170)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int nmax = 16;
int n,m;
int a[nmax+5][nmax+5];
int sumcol[nmax+5];
ll mx;
void flip(int k) {
for(int j=1; j<=m; j++) {
a[k][j] *= -1;
sumcol[j] += 2 * a[k][j];
}
}
void compute() {
ll s = 0;
for(int j=1; j<=m; j++)
s += 1LL * max(sumcol[j], -sumcol[j]);
mx = max(mx,s);
}
void bt(int k) {
if(k==n+1) {
compute();
return ;
}
bt(k+1);
flip(k);
bt(k+1);
}
int main () {
ifstream f ("flip.in");
ofstream g ("flip.out");
f >> n >> m;
for(int i=1; i<=n; i++)
for(int j=1; j<=m; j++) {
f >> a[i][j];
sumcol[j] += a[i][j];
}
bt(1);
g << mx;
return 0;
}