Pagini recente » Cod sursa (job #1882585) | Cod sursa (job #1029167) | Cod sursa (job #2167030) | Cod sursa (job #906216) | Cod sursa (job #1938205)
#include <fstream>
#include <stdio.h>
#define maxim 16
using namespace std;
int v[maxim][maxim];
char lin[maxim+1];
char col[maxim+1];
void inc_lin ( int l ) {
int i = 0;
while ( i < l && lin[i] == 1 ) {
lin[i] = 0;
i++;
}
if ( i < l ) {
lin[i] = 1;
}
}
void inc_col ( int c ) {
int j = 0;
while ( j < c && col[j] == 1 ) {
col[j] = 0;
j++;
}
if ( j < c ) {
col[j] = 1;
}
}
long long getsum ( int l, int c ) {
long long s = 0;
int i, j;
for ( i = 0; i < l; i++ )
for ( j = 0; j < c; j++ )
if ( lin[i] + col[j] == 1 )
s -= v[i][j];
else
s += v[i][j];
return s;
}
int main () {
ifstream fin ( "flip.in" );
ofstream fout ( "flip.out" );
int l, c;
fin>>l>>c;
int i, j;
for ( i = 0; i < l; i++ )
for ( j = 0; j < c; j++ )
fin>>v[i][j];
long long s = 0LL, smax = -1000000LL;
for ( i = 0; i < 1<<l; i++, inc_lin ( l ) )
for ( j = 0; j < 1<<c; j++, inc_col ( c ) ) {
s = getsum ( l, c );
if ( s > smax )
smax = s;
}
fout<<smax<<'\n';
fin.close ();
fout.close ();
return 0;
}