Pagini recente » Cod sursa (job #383954) | Cod sursa (job #714755) | Cod sursa (job #808437) | Cod sursa (job #2375235) | Cod sursa (job #3295269)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("flip.in");
ofstream g("flip.out");
int i,j,m,n,a[20][20],aux[20][20],l,c,k,x[100],s,p;
long long maxx=-100000000000;
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[20][20])
{
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;
}