Pagini recente » Cod sursa (job #2591883) | Cod sursa (job #2562890) | Cod sursa (job #1532551) | Cod sursa (job #3226775) | Cod sursa (job #1840421)
#include <cstdio>
#define BIT(k) (1<<(k))
#define max(a, b) (a>b?a:b)
using namespace std;
int nl, nc;
int mat[20][20];
int scol[20], sc, smax = -1000000000;
int main()
{
int i, j, c;
freopen("flip.in", "r", stdin);
freopen("flip.out", "w", stdout);
scanf("%d%d", &nl, &nc);
for(i = 0; i < nl; i++)
{
for(j = 0; j < nc; j++)
{
scanf("%d", &mat[i][j]);
}
}
for(c = 0; c < BIT(nl); c++)
{
sc = 0;
for(j = 0; j < nc; j++)
{
scol[j] = 0;
for(i = 0; i < nl; i++)
{
if((c & BIT(i)) != 0)
{
sc -= mat[i][j];
scol[j] -= mat[i][j];
}
else
{
sc += mat[i][j];
scol[j] += mat[i][j];
}
}
}
for(j = 0; j < nc; j++)
{
if(scol[j] < 0) sc -= 2 * scol[j];
}
smax = max(smax, sc);
}
printf("%d", smax);
return 0;
}