Cod sursa(job #319236)

Utilizator mentallysafenotPerian Bogdan mentallysafenot Data 30 mai 2009 21:32:23
Problema Jocul Flip Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <fstream>

using namespace std;
fstream f,g;

long flipper[16][16];
int a, b;
int m, n;
long maxi;

long summer(int i,int j)
{
   long sum=0;
   if(i==-1) 
     a = 0;
   else 
     a = 1 << i;
   if(j == -1 ) 
      b = 0;
   else
      b = 1 << j;
	
	for(i=0;i<m;i++)
	  for(j=0;j<n;j++)
	     sum+= (a&(1<<i)?-1:1)*(b&(1<<j)?-1:1)*flipper[i][j];
    
   return sum;
}

int main()
{
  f.open("flip.in",fstream::in);
  f >> m >> n;
  int i,j;
  for(i=0;i<m;i++)
     for(j=0;j<n;j++)
	   {
	    f >> flipper[i][j];
         }		
  
  long aux;
  
  
  for(i=-1;i<m;i++)
    for(j=-1;j<n;j++)
	  {
	     aux = summer(i,j);
		 if(aux>maxi)
		    maxi = aux;
	  }
  
  g.open("flip.out",fstream::out);
  g << maxi << "\n";
  g.close();
  return 0;
}