Pagini recente » Cod sursa (job #2185693) | Cod sursa (job #2209484) | Cod sursa (job #1055842) | Cod sursa (job #96517) | Cod sursa (job #730635)
Cod sursa(job #730635)
#include<stdio.h>
int semn[16][2],n,m,i,j,a[16][16],max1;
void suma()
{int t=0;
for(i=0;i<n;i++) for(j=0;j<m;j++) t+=a[i][j]*semn[i][0]*semn[j][1];
if(t>max1) max1=t;
}
void back(int x, int y)
{if(x==n && y==m) suma();
else {if(x<=(n-1)) {semn[x][0]=-1;back(x+1,y);}
if(y<=(m-1)) {semn[y][1]=-1;back(x,y+1);}
if(x<=(n-1)) {semn[x][0]=1;back(x+1,y);}
if(y<=(m-1)) {semn[y][1]=1;back(x,y+1);}
}
}
int main()
{freopen("flip.in","r",stdin);
freopen("flip.out","w",stdout);
scanf("%d%d",&n,&m);
for(i=0;i<n;i++) for(j=0;j<m;j++) scanf("%d",&a[i][j]);
back(0,0);
printf("%d",max1);
return 0;
}