Pagini recente » Cod sursa (job #1407327) | Cod sursa (job #1944571) | Borderou de evaluare (job #528079) | Cod sursa (job #289309) | Cod sursa (job #3195211)
#include <fstream>
using namespace std;
ifstream in( "flip.in" );
ofstream out( "flip.out" );
#define MAXN 16
int array[ MAXN ][ MAXN ];
bool lines[ MAXN ];
int m, n, maxx;
void read( )
{
in >> n >> m;
for( int i = 0; i < n; i++ )
{
for( int j = 0; j < m; j++ )
{
in >> array[ i ][ j ];
}
}
}
void backt( int pos )
{
if( pos == m )
{
int total = 0;
for( int i = 0; i < n; i++ )
{
int colsum = 0;
for( int j = 0; j < m; j++ )
{
if( lines[ j ] == true )
{
colsum -= array[ i ][ j ];
}
else
{
colsum += array[ i ][ j ];
}
}
if( colsum < 0 )
{
colsum *= ( - 1 );
}
total += colsum;
}
maxx = std::max( maxx, total );
}
else
{
lines[ pos ] = true;
backt( pos + 1 );
lines[ pos ] = false;
backt( pos + 1 );
}
}
void solve( )
{
read( );
backt( 0 );
out << maxx;
}
int main()
{
solve( );
return 0;
}