Pagini recente » Cod sursa (job #249175) | Cod sursa (job #967675) | Cod sursa (job #1009653) | Cod sursa (job #2697238) | Cod sursa (job #3295263)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("flip.in");
ofstream g("flip.out");
int i,j,m,n,a[100][100],aux[100][100],l,c,k,x[100],s,maxx=-1000001,p;
int revenire()
{
for(i=0;i<n;i++)
for(j=0;j<m;j++)
a[i][j]=aux[i][j];
return 0;
}
int linie (int l)
{
for(j=0;j<m;j++)
a[l][j]*=-1;
return 0;
}
int coloana (int c)
{
for(i=0;i<n;i++)
a[i][c]*=-1;
return 0;
}
int suma (int a[100][100])
{
s=0;
for(i=0;i<n;i++)
for(j=0;j<m;j++)
s+=a[i][j];
return s;
}
int max (int s)
{
if(maxx<s)
maxx=s;
return maxx;
}
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;
}