Cod sursa(job #769527)

Utilizator cnt_tstcont teste cnt_tst Data 19 iulie 2012 18:59:19
Problema Jocul Flip Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <fstream>

using namespace std;

int V[20];
int N, i, s, S, n, j, m, Max;

int a[20][20], b[20][20];

int main() {
	ifstream f("flip.in");
	ofstream g("flip.out");
	f>>n>>m;
	for(i=1;i<=n;i++)
		for(j=1;j<=m;j++)
			f>>a[i][j];
	f.close();
	
	while (V[0] == 0) {
	
		i=m;
		while (V[i] == 1)
			V[i--] = 0;
		V[i] = 1;
		
		for (i=1;i<=n;i++)
			for (j=1;j<=m;j++)
				if (V[j] == 1)
					b[i][j] = -a[i][j];
				else
					b[i][j] = a[i][j];
		
		S = 0;
		
		for(i=1;i<=n;i++)
		{
			s=0;
			for(j=1;j<=m;j++)
			{
				s=s+b[i][j];
			}
			if (s > 0)
				S+=s;
			else
				S-=s;
		}
		
		if(S>Max) 
			Max=S;
			
	}
	g<<Max;
	
	return 0;
}