Pagini recente » Cod sursa (job #2495202) | Cod sursa (job #2138550) | Cod sursa (job #2936673) | Cod sursa (job #664374) | Cod sursa (job #2398487)
#include <fstream>
using namespace std;
ifstream cin("flip.in");
ofstream cout("flip.out");
int n, m, a[20][20];
int main()
{
cin >> n >> m;
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
cin >> a[i][j];
int nmax = (1 << n) - 1;
int mmax = (1 << m) - 1;
int smax = 0;
for(int i = 0; i <= nmax; i++)
for(int j = 0; j <= mmax; j++)
{
int s = 0;
for(int x = 0; x < n; x++)
for(int y = 0; y < m; y++)
{
int val = a[x][y];
if((1 << x) & i)
val *= -1;
if((1 << y) & j)
val *= -1;
s += val;
}
if(s > smax)
smax = s;
}
cout << smax;
return 0;
}