Pagini recente » Cod sursa (job #722581) | Cod sursa (job #2321280) | Cod sursa (job #2899125) | Cod sursa (job #911397) | Cod sursa (job #233291)
Cod sursa(job #233291)
#include<stdio.h>
#include<values.h>
#include<math.h>
FILE*f=fopen("flip.in","r");
FILE*g=fopen("flip.out","w");
int m,n,d[2]={1,-1},st[17],st1[17];
long a[17][17],max=-MAXLONG,S;
void citire()
{int i,j;
fscanf(f,"%d%d",&n,&m);
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
fscanf(f,"%ld",&a[i][j]);
}
void bkt(int k)
{int i,j,x,p;
long s,s1;
for(i=0;i<2;i++)
{st[k]=d[i];
if(k==n) {S=0;
for(j=1;j<=m;j++)
{s=s1=0;
x=-1;
for(p=1;p<=n;p++)
{s+=a[p][j]*st[p]*x;
s1+=a[p][j]*st[p]*x*x;}
if(s>s1) {st1[j]=x;
S+=s;}
else {st1[j]=x*x;
S+=s1;}
}
if(S>max) max=S;
}
else bkt(k+1);
}
}
int main()
{citire();
bkt(1);
fprintf(g,"%ld",max);
fcloseall();
return 0;
}