Pagini recente » Cod sursa (job #1167935) | Cod sursa (job #2890596) | Cod sursa (job #2158532) | Cod sursa (job #2109482) | Cod sursa (job #356004)
Cod sursa(job #356004)
#include <stdio.h>
int n,m,max=0;
int mat[17][17];
bool col[17],lin[17];
void back(int);
void back2(int);
int suma();
int main ()
{
freopen ("flip.in","r",stdin);
freopen ("flip.out","w",stdout);
scanf ("%d%d",&n,&m);
for (int i=1;i<=n;++i)
for (int j=1;j<=m;++j)
scanf ("%d",&mat[i][j]);
back(1);
printf ("%d",max);
return 0;
}
void back(int p)
{
if (p>m)
{
back2(1);
return;
}
col[p]=0;
back(p+1);
col[p]=1;
back(p+1);
}
void back2(int p)
{
if (p>n)
{
int x=suma();
if (x>max)
max=x;
return;
}
lin[p]=0;
back2(p+1);
lin[p]=1;
back2(p+1);
}
int suma()
{
int s=0;
for (int i=1;i<=n;++i)
for (int j=1;j<=m;++j)
s+=mat[i][j]*(col[j]*2-1)*(lin[i]*2-1);
return s;
}