Pagini recente » Cod sursa (job #1404463) | Cod sursa (job #1247423) | Cod sursa (job #1059224) | Cod sursa (job #2707678) | Cod sursa (job #178187)
Cod sursa(job #178187)
#include<fstream.h>
#include<iostream.h>
#include<math.h>
int main(void)
{
long int l,c,i,j,a,x[17][17],suma,su,tot=0,k,y[17][17];
fstream f,g;
f.open("flip.in",ios::in);
g.open("flip.out",ios::out);
f>>l;
f>>c;
for(i=1;i<=l;i++)
for(j=1;j<=c;j++)
f>>y[i][j];
for(i=0;i<=pow(2,l)-1;i++)
{
for(j=1;j<=l;j++)
for(k=1;k<=l;k++)
x[j][k]=y[j][k];
suma=0;
for(j=0;j<=l-1;j++)
if((i>>j)%2==1)
for(k=1;k<=c;k++)
x[j+1][k]=x[j+1][k]*(-1);
for(j=1;j<=c;j++)
{
su=0;
for(k=1;k<=l;k++)
su=su+x[k][j];
if(su<0)
for(k=1;k<=l;k++)
x[k][j]=x[k][j]*(-1);
}
for(j=1;j<=l;j++)
for(k=1;k<=c;k++)
suma=suma+x[j][k];
if(suma>tot)
tot=suma;
}
for(i=0;i<=pow(2,c)-1;i++)
{
suma=0;
for(j=1;j<=l;j++)
for(k=1;k<=l;k++)
x[j][k]=y[j][k];
for(j=0;j<=c-1;j++)
if((i>>j)%2==1)
for(k=1;k<=l;k++)
x[k][j+1]=x[k][j+1]*(-1);
for(j=1;j<=l;j++)
{
su=0;
for(k=1;k<=c;k++)
su=su+x[j][k];
if(su<0)
for(k=1;k<=c;k++)
x[j][k]=x[j][k]*(-1);
}
for(j=1;j<=l;j++)
for(k=1;k<=c;k++)
suma=suma+x[j][k];
if(suma>tot)
tot=suma;
}
g<<tot;
g.close();
f.close();
return 0;
}