Pagini recente » Cod sursa (job #3135349) | Borderou de evaluare (job #1072893) | daupentrumata | Cod sursa (job #2534316) | Cod sursa (job #2649723)
#include <bits/stdc++.h>
using namespace std;
ifstream in("flip.in");
ofstream out("flip.out");
int n, m;
int mat[20][20];
int sp[20];
int maxim = -1000000000;
void bkt(int poz)
{
//cout << poz << endl;
if(poz == n)
{
int sum = 0;
for(int j = 0; j < m; j++)
sum += max(sp[j], -sp[j]);
maxim = max(maxim, sum);
return;
}
for(int j = 0; j < m; j++)
sp[j] += mat[poz][j];
bkt(poz+1);
for(int j = 0; j < m; j++)
sp[j] -= 2*mat[poz][j];
bkt(poz+1);
for(int j = 0; j < m; j++)
sp[j] += mat[poz][j];
}
int main()
{
in >> n >> m;
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
in >> mat[i][j];
bkt(0);
out << maxim;
}