Pagini recente » Cod sursa (job #2269735) | Cod sursa (job #2058019) | Cod sursa (job #2625045) | Cod sursa (job #2332517) | Cod sursa (job #2616940)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin ("flip.in");
ofstream fout ("flip.out");
int mat[16][16], m, n, smax=-100000000, operatie[16];
int calc_sum_tot()
{
int i, j, s_col, s_totala=0;
for(j=0;j<m;j++)
{
s_col=0;
for(i=0;i<n;i++)
{
if(operatie[i]==1)
s_col-=mat[i][j];
else
s_col+=mat[i][j];
}
if(s_col<0)
s_col=-s_col;
s_totala+=s_col;
cout << s_totala << '\n';
}
return s_totala;
}
void bkt_flip(int pos)
{
if(pos==n)
{
int s=calc_sum_tot();
if(s>smax)
smax=s;
}
else
{
int i;
for(i=0;i<=1;i++)
{
operatie[pos]=i;
bkt_flip(pos+1);
}
}
}
int main()
{
int l, c;
fin >> n >> m;
for(l=0;l<n;l++)
for(c=0;c<m;c++)
fin >> mat[l][c];
bkt_flip(0);
fout << smax;
return 0;
}