Pagini recente » Cod sursa (job #2905095) | Cod sursa (job #3165341) | Cod sursa (job #1418686) | Cod sursa (job #2469287) | Cod sursa (job #2398495)
#include <fstream>
using namespace std;
ifstream cin("flip.in");
ofstream cout("flip.out");
int n, m, a[20][20], vizx[20], lin[20], col[20], tot;
int main()
{
cin >> n >> m;
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
{
cin >> a[i][j];
lin[i] += a[i][j];
col[j] += a[i][j];
tot += a[i][j];
}
int nmax = (1 << n) - 1;
int mmax = (1 << m) - 1;
int smax = tot;
for(int i = 0; i <= nmax; i++)
for(int j = 0; j <= mmax; j++)
{
int k = 0;
int s = tot;
for(int x = 0; x < n; x++)
if((1 << x) & i)
{
s -= 2 * lin[x];
vizx[++k] = x;
}
for(int y = 0; y < m; y++)
if((1 << y) & j)
{
s -= 2 * col[y];
for(int q = 1; q <= k; q++)
s += 4 * a[vizx[q]][y];
}
if(s > smax)
smax = s;
}
cout << smax;
return 0;
}