Pagini recente » Statistici Paduraru Razvan (razvanpaduraru) | Cod sursa (job #1880879) | Cod sursa (job #1669086) | Cod sursa (job #2044883) | Cod sursa (job #2489546)
#include <bits/stdc++.h>
using namespace std;
ifstream f("flip.in");
ofstream g("flip.out");
int n, m, S = -256000010 , nr, a[17][17];
void suma(), Bk(int), transformare(int);
int main()
{
f >> n >> m;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
f >> a[i][j];
Bk(1);
g << S;
return 0;
}
void suma()
{
int temp_s = 0;
for(int i = 1; i <= n; i++)
{
int s = 0;
for(int j = 1; j <= m; j++)
s += a[i][j];
if(s < 0)
s = -s;
temp_s += s;
}
S = max(S, temp_s);
}
void Bk(int col)
{
if(col == m + 1)
{
suma();
return;
}
Bk(col + 1);
transformare(col);
Bk(col + 1);
}
void transformare(int col)
{
for(int i = 1; i <= n; i++)
a[i][col] = -a[i][col];
}