Pagini recente » Cod sursa (job #957804) | Cod sursa (job #2682293) | Cod sursa (job #2842815) | Cod sursa (job #1577246) | Cod sursa (job #319246)
Cod sursa(job #319246)
#include <fstream>
#include <cmath>
using namespace std;
fstream f,g;
long flipper[16][16];
int a, b;
int m, n;
long maxi;
long summer(int i,int j)
{
long sum=0;
int a,b;
for(a=0;a<m;a++)
for(b=0;b<n;b++)
sum+= (i&(1<<a)?-1:1)*(j&(1<<b)?-1:1)*flipper[a][b];
return sum;
}
int main()
{
f.open("flip.in",fstream::in);
f >> m >> n;
int i,j;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
f >> flipper[i][j];
}
long aux;
int q,w;
q = pow(2,(float)m)+1;
w = pow(2,(float)n)+1;
for(i=0;i<q;i++)
for(j=0;j<w;j++)
{
aux = summer(i,j);
if(aux>maxi)
maxi = aux;
}
g.open("flip.out",fstream::out);
g << maxi << "\n";
g.close();
return 0;
}