Pagini recente » Cod sursa (job #1728572) | Cod sursa (job #334118) | Cod sursa (job #3257853) | Cod sursa (job #318643) | Cod sursa (job #1957571)
#include <fstream>
#include <stdio.h>
#define maxim 16
using namespace std;
long long 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;
}
}
long long _max ( long long a, long long b ) {
if ( a > b )
return a;
else
return b;
}
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;
int cs, k;
for ( i = 0; i < 1<<l; i++ ) {
s = 0LL;
for ( j = 0; j < c; j++ ) {
cs = 0;
for ( k = 0; k < l; k++ ) {
if ( lin[k] == 0 )
cs += v[k][j];
else
cs -= v[k][j];
}
if ( cs < 0 ) {
col[j] = 1;
s -= cs;
}
else {
col[j] = 0;
s += cs;
}
}
smax = _max ( smax, s );
inc_lin ( l );
}
fout<<smax<<'\n';
fin.close ();
fout.close ();
return 0;
}