Pagini recente » Cod sursa (job #2895563) | Cod sursa (job #1038883) | Cod sursa (job #1449533) | Cod sursa (job #32128) | Cod sursa (job #3296430)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("flip.in");
ofstream g("flip.out");
int i,j,m,n,a[16][16],aux[16][16],l,c,k,x[32],s,p;
long long maxx=-1000000000000;
void revenire()
{
for(i=0;i<n;i++)
for(j=0;j<m;j++)
a[i][j]=aux[i][j];
}
void linie (int l)
{
for(j=0;j<m;j++)
a[l][j]*=-1;
}
void coloana (int c)
{
for(i=0;i<n;i++)
a[i][c]*=-1;
}
void suma (int a[16][16])
{
s=0;
for(i=0;i<n;i++)
for(j=0;j<m;j++)
s+=a[i][j];
}
void max (int s)
{
if(maxx<s)
maxx=s;
}
void back(int k){
for(int ff=x[k-1]+1;ff<=(n+m);++ff)
{
x[k]=ff;
for(p=1;p<=k;++p)
if(x[p]<=n&&x[p]>0)
linie(x[p]-1);
else
coloana(x[p]-(n+1));
suma(a);
max(s);
revenire();
back(k+1);
}
}
int main()
{
f>>n>>m;
for(i=0;i<n;i++)
for(j=0;j<m;j++)
{
f>>a[i][j];
aux[i][j]=a[i][j];
}
back(1);
g<<maxx;
return 0;
}