Pagini recente » Monitorul de evaluare | Istoria paginii utilizator/victordumitrescu | Cod sursa (job #153931) | Denis S | Cod sursa (job #606492)
Cod sursa(job #606492)
#include <iostream>
#include <fstream>
using namespace std;
int M,N,i,j;
long mat[17][17],S;
char n[17];
long modul(long numar)
{
if (numar<0) return (-1)*numar;
else return numar;
}
void back (int x)
{
int l;
if (x>N)
{
long Ss=0,Scoloana,crt;
for (j=1; j<=M; j++)
{
Scoloana=0;
for (i=1; i<=N; i++)
if (n[i]) Scoloana+=mat[i][j];
else Scoloana+=mat[i][j]*(-1);
Ss+=modul(Scoloana);
}
if (Ss>S) S=Ss;
}
else for (l=0; l<=1; l++)
{
n[x]=l;
back(x+1);
}
}
int main()
{
freopen("flip.in", "r", stdin);
freopen("flip.out", "w", stdout);
scanf("%d %d", &N, &M);
for (i=1; i<=N; i++)
for (j=1;j<=M ;j++) scanf("%d", &mat[i][j]);
back(1);
printf("%d\n", S);
return 0;
}