Cod sursa(job #542415)

Utilizator andunhillMacarescu Sebastian andunhill Data 26 februarie 2011 13:08:52
Problema Pixels Scor 10
Compilator cpp Status done
Runda Romanian Master in Mathematics and Sciences 2011, Ziua 2 Marime 1.09 kb
#include<fstream>
using namespace std;
ifstream f("pixels.in");
ofstream g("pixels.out");
struct dif 
{	int sus,dr,jos,st;
};
int N,mg;
int A[101][101];
int B[101][101];
dif a[101][101];
char mat[101][101];
void read(int N,int a[101][101])
{	int i,j;
	for(i=1;i<=N;i++)
		for(j=1;j<=N;j++)
			f>>a[i][j];
}
int maxx(int a,int b,int c,int d)
{	int m;
	m=max(a,max(b,max(c,d)));
	return m;
}
void det()
{	int sa,sn,sd; sa=sn=sd=0;
	int i,j;
	for(i=1;i<=N;i++)
		for(j=1;j<=N;j++)
		{	if(mat[i][j]=='A')
				sa+=A[i][j];
			else sn+=B[i][j];
			if(mat[i][j]!=mat[i-1][j]) sd+=a[i][j].sus;
			if(mat[i][j]!=mat[i][j+1]) sd+=a[i][j].dr;
		}
	mg=max(mg,sa+sn-sd);
}
void go(int x,int y)
{	if(x>N) { det(); return; }
	mat[x][y]='A';
	if(y==N) go(x+1,1);
	else go(x,y+1);
	mat[x][y]='N';
	if(y==N) go(x+1,1);
	else go(x,y+1);
}
int main()
{	int i,j,alb,neg;
	int sa,sn,sd; sa=sn=sd=0;
	f>>N;
	read(N,A);
	read(N,B);
	for(i=1;i<=N;i++)
		for(j=1;j<=N;j++)
			f>>a[i][j].sus>>a[i][j].dr>>a[i][j].jos>>a[i][j].st;
	go(1,1);
	g<<mg;
	f.close();
	g.close();
	return 0;
}