Pagini recente » Cod sursa (job #2682865) | Cod sursa (job #930516) | Cod sursa (job #1738799) | Cod sursa (job #1032320) | Cod sursa (job #959805)
Cod sursa(job #959805)
#include <fstream>
using namespace std;
const int dMax = 17;
int N, M, sol;
int A[dMax][dMax], bin[dMax + 1];
void nextBinary(int V[])
{
int position = 1;
V[position]++;
while (V[position] == 2) {
V[position + 1]++;
V[position++] = 0;
}
}
int getMax(int A[dMax][dMax])
{
int res = 0;
for (int j = 1; j <= M; j++) {
int sum = 0;
for (int i = 1; i <= N; i++)
sum = sum + A[i][j];
if (sum < 0) res = res - sum;
else res = res + sum;
}
return res;
}
int main()
{
ifstream fin("flip.in");
ofstream fout("flip.out");
fin >> N >> M;
for (int i = 1; i <= N; i++)
for (int j = 1; j <= M; j++)
fin >> A[i][j];
while (bin[N + 1] == 0) {
int Aux[dMax][dMax];
for (int i = 1; i <= N; i++)
for (int j = 1; j <= M; j++)
Aux[i][j] = A[i][j] * (bin[i] == 0 ? 1 : -1);
sol = max(sol, getMax(Aux));
nextBinary(bin);
}
fout << sol;
}