Pagini recente » Cod sursa (job #3215607) | Cod sursa (job #1463908)
#include<iostream>
#include<fstream>
#include<algorithm>
using namespace std;
ifstream fin("flip.in");
ofstream fout("flip.out");
int s,scol,a[100][100],N,M;
int st[100];
int suma=-9999999;
void Citire()
{
int i,j;
fin>>M>>N;
for (i=1;i<=M;i++)
for (j=1;j<=N;j++)
fin>>a[i][j];
}
void Afisare()
{
int i,j;
scol=0;
for (i=1;i<=N;i++)
{
s=0;
for (j=1;j<=M;j++)
{
if (st[j]==1) s=s+a[j][i]*(-1);
else s+=a[j][i];
}
if (-s>s) scol+=-s;
else scol+=s;
}
suma=max(suma,scol);
}
void Back(int top)
{
int i;
if (top==M+1) Afisare();
else for (i=0;i<=1;i++)
{
st[top]=i;
Back(top+1);
}
}
int main ()
{
Citire();
Back(1);
fout<<suma<<"\n";
fin.close();
fout.close();
return 0;
}