Cod sursa(job #1126565)

Utilizator dec0o0dinu pinu dec0o0 Data 27 februarie 2014 02:13:00
Problema Jocul Flip Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
vector<vector<int> > a;
int n,m;
int greedy(int submultime){
	int s=0,total = 0;

	for (int i=0;i<m;i++){
		s=0;
		for(int j=0;j<n;j++)
			if ((1<<j) & submultime)
				s=s+a[j][i]*(-1);
			else
				s+=a[j][i];
		if (s<0 ) total+=s*(-1);
		else total+=s;
	}

	return total;

}
int rezolva1(){
	int max = greedy(0), c, max_bit;
	max_bit = 1<<n;
	for (int i=1;i<max_bit;i++){
		c = greedy(i);
		if (c>max) max = c;
	}
	return max;
}
int main(){
	ifstream f("flip.in");
	ofstream g("flip.out");
	f>>n>>m;
	a = vector<vector<int> > (n, vector<int>(m,0));
	for (int i=0;i<n;i++)
		for (int j=0;j<m;j++)
			f>>a[i][j];
	g<<rezolva1();
	f.close();
	g.close();
return 0;
}