Pagini recente » Cod sursa (job #1518146) | Cod sursa (job #2362116) | Cod sursa (job #1767016) | Cod sursa (job #2378470) | Cod sursa (job #2084026)
#include <bits/stdc++.h>
#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i <= n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define V vector<int>
#define VP vector<pair<int, int> >
#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
#ifdef _WIN32
#include <windows.h>
#define print(x) PRINT(x, #x)
template<typename T> inline const void PRINT(T VARIABLE, string NAME)
{
#ifndef ONLINE_JUDGE /// ONLINE_JUDGE IS DEFINED ON CODEFORCES
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, 10);
cerr << NAME << " = " << VARIABLE;
SetConsoleTextAttribute(hConsole, 7);
cerr << '\n';
#endif
}
#else
#define print(x) 0
#endif
typedef long long ll;
typedef unsigned long long ull;
const ll INFLL = 2 * (ll)1e18 + 100;
const int INFINT = 2 * (int)1e9 + 100;
const double PI = atan(1) * 4;
const double EPS = 1e-12;
const int SEED = 1e3 + 7;
const int MOD = 1e9 + 7; /// careful here (7 or 9, 66.. etc)
const int NMAX = 1e6 + 5;
ifstream fin("flip.in");
ofstream fout("flip.out");
#define cin fin
#define cout fout
int n, m;
int mat[20][20], sum_pos[20], sum_neg[20];
int sol = -INFINT;
int main()
{
FASTIO;
cin >> n >> m;
for1(i, n) for1(j, m)
{
cin >> mat[i][j];
if(mat[i][j] > 0) sum_pos[j] += mat[i][j];
else sum_neg[j] -= mat[i][j];
}
for(int i = (1 << n) - 1; i >= 0; i--)
{
vector<int> s_pos(20), s_neg(20);
for(int j = 0; j < n; j++) if((i >> j) & 1)
{
for1(col, m)
{
if(mat[j + 1][col] > 0) s_pos[col] += mat[j + 1][col];
else s_neg[col] -= mat[j + 1][col];
}
}
int sum = 0;
for1(j, m)
{
sum += max(sum_pos[j] - s_pos[j] + s_neg[j], sum_neg[j] + s_pos[j] - s_neg[j]) -
min(sum_pos[j] - s_pos[j] + s_neg[j], sum_neg[j] + s_pos[j] - s_neg[j]);
}
sol = max(sol, sum);
}
cout << sol;
return 0;
}