Cod sursa(job #283764)

Utilizator yotherockerPuia Tudor yotherocker Data 19 martie 2009 18:57:15
Problema Jocul Flip Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <fstream.h>
#define El 16
    
long A[El][El],B[El],aux1,aux2,max;   
unsigned int n,m,i,j,x;   


main()   
{     
	ifstream In("flip.in");   
        ofstream Out("flip.out");
	In>>n>>m;   
	for(i=0;i<n;i++)     
    	   for(j=0;j<m;j++)  In>>A[i][j];
	In.close();
     
	while(x>=0) 
	{  
		if(B[x]==1) 
		{ 
			B[x]=0;     
                        x--;     
                        continue;     
                }     
                else if(B[x]==-1) 
		{
			B[x]=1;
		}     
                     
                else B[x]=-1;
     
                if(x==m) 
		{ 
			aux1=0;     
                        for(i=0;i<n;i++) 
			{ 
				aux2=0;     
                                for(j=0;j<m;j++)  aux2+=A[i][j]*B[j];     
                                if(aux2<0)  aux1-=aux2;     
				else aux1+=aux2;
                        }   
  
                        if(aux1>max) max=aux1;    
                        continue;     
                 }   
                 x++;     
        }     
	Out<<max<<'\n';
        
	Out.close();
	return 0;     
}