Pagini recente » Cod sursa (job #1586045) | Cod sursa (job #1752694) | Cod sursa (job #334678) | Cod sursa (job #2084792) | Cod sursa (job #350053)
Cod sursa(job #350053)
#include<stdio.h>
FILE *f=fopen("flip.in","r");
FILE *g=fopen("flip.out","w");
int n,m,i,j;
long a[17][17];
long s,max1=0,max2=-2500000000;
int Suma(long a[17][17],long s)
{int i,j;
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
s=s+a[i][j];
return s;
}
void ScmbC(long a[17][17],int j)
{int x;
for(x=1;x<=n;x++)
a[x][j]=a[x][j]*(-1);
}
void ScmbR(long a[17][17], int i)
{int y;
for(y=1;y<=m;y++)
a[i][y]=a[i][y]*(-1);
}
int Maxim(long a[17][17],long max2,int i,int j)
{long long sum;
sum=Suma(a,0);
if(sum>max2)max2=sum;
ScmbC(a,j);
sum=Suma(a,0);
if(sum>max2)max2=sum;
ScmbR(a,i);
sum=Suma(a,0);
if(sum>max2)max2=sum;
ScmbC(a,j);
a[i][j]=a[i][j]*(-1);
sum=Suma(a,0);
if(sum>max2)max2=sum;
ScmbR(a,i);
return max2;
}
int main()
{fscanf(f,"%d%d",&n,&m);
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
fscanf(f,"%ld",&a[i][j]);
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
{s=Maxim(a,0,i,j);
if(s>max1)max1=s;}
fprintf(g,"%lld",max1);
fcloseall();
return 0;
}