Pagini recente » Cod sursa (job #340433) | Cod sursa (job #1043428) | Cod sursa (job #1511765) | Cod sursa (job #3171867) | Cod sursa (job #939974)
Cod sursa(job #939974)
#include<cstdio>
int n,m,v[20][20],rez,st[20];
void check()
{
int i,j,stemp,smat;
smat=0;
for(i=1;i<=m;i++)
{
stemp=0;
for(j=1;j<=n;j++)
if(st[j]==1)
stemp=stemp+v[j][i];
else
stemp=stemp-v[j][i];
if(stemp>0)
smat=smat+stemp;
else
smat=smat-stemp;
}
if(smat>rez)
rez=smat;
}
void back(int k)
{
int i;
if(k==n+1)
check();
else
for(i=0;i<2;i++)
{
st[k]=i;
back(k+1);
}
}
int main()
{
int i,j;
freopen("flip.in","r",stdin);
freopen("flip.out","w",stdout);
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
scanf("%d",&v[i][j]);
back(1);
printf("%d",rez);
return 0;
}