Cod sursa(job #700324)

Utilizator Alecu7Chiriac Alexandru Alecu7 Data 1 martie 2012 09:31:35
Problema Jocul Flip Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <fstream>
#include <math.h>
int m[17][17], v[17];
using namespace std;
int main()
{
	ifstream f("flip.in");
	ofstream g("flip.out");
	int N,M,max,i,j,t,S,St,k;
	f>>N; f>>M; max=0;
	for(i=1;i<=N;i++)
	{	for(j=1;j<=M;j++)
		{ f>>m[i][j];
		  max=max+m[i][j];
		}
	}
	for(k=1;k<=pow(2,M)-1;k++)
	{	t=k; St=0;
		for(j=1;j<=M;j++)
		{
			v[j]=t%2;
			t=t/2;
		}
		for(i=1;i<=N;i++)
		{
			S=0;
			for(j=1;j<=M;j++)
			{
				if(v[j]==1) S=S+m[i][j];
				else S=S-m[i][j];
			}
			if(S>0)
				St=St+S;
			else 
				St=St-S;
		}
		if(St>max)
			max=St;
	}
	g<<max;
	f.close();g.close();return 0;
}