Pagini recente » Cod sursa (job #1136179) | Cod sursa (job #2706903) | Cod sursa (job #2791101) | Cod sursa (job #495408) | Cod sursa (job #414286)
Cod sursa(job #414286)
#include <fstream>
#include <math.h>
using namespace std;
ifstream in("flip.in");
ofstream out("flip.out");
#define modul(n) (n>0?n:-n)
int rezmax=-32000,n,m;
int flip[17];
int a[17][17];
void calculeaza()
{
int rez=0,i,j;
for(i=1;i<=n;i++)
{
int sum=0;
for(j=1;j<=m;j++)
sum+=a[i][j]*flip[j];
rez+=abs(sum);
}
if(rez>rezmax)
rezmax=rez;
}
void back(int k)
{
if(k-1==m)
calculeaza();
else
{
flip[k]=1;
back(k+1);
flip[k]=-1;
back(k+1);
}
}
int main ()
{
int i,j;
in>>n>>m;
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
in>>a[i][j];
back(1);
out<<rezmax;
return 0;
}