Pagini recente » Cod sursa (job #861580) | Cod sursa (job #3141855) | Cod sursa (job #2741304) | Cod sursa (job #691027) | Cod sursa (job #542532)
Cod sursa(job #542532)
#include<stdio.h>
#include<algorithm>
using namespace std;
int N,v[1000],n,a[102][120],b[15][15],c[23][23][6],p[1010],nr,m[12][120],maxim;
int calc()
{int S=0;
for(int i=1;i<=N;++i)
for(int j=1;j<=N;++j)
{
if(m[i][j])
S+=a[i][j];
else S+=b[i][j];
if(m[i-1][j]==m[i][j])
S-=c[i][j][1];
if(m[i][j+1]==m[i][j])
S-=c[i][j][2];
if(m[i+1][j]==m[i][j])
S-=c[i][j][3];
if(m[i][j-1]==m[i][j])
S-=c[i][j][4];
}
return S;
}
void back(int x,int y)
{
if(x==N+1&&y==N)
for(int i=1;i<=N;++i)
{
maxim=max(maxim,calc());
}
else
{
if(x==N+1)
x=1,y=y+1;
m[x][y]=0;
back(x+1,y);
m[x][y]=1;
back(x+1,y);
}
}
int main()
{
freopen("pixels.in","r",stdin);
freopen("pixels.out","w",stdout);
scanf("%d",&N);
for(int i=0;i<=N+1;++i)
{
m[0][i]=2;
m[i][0]=2;
m[N+1][i]=2;
m[i][N+1]=0;
}
for(int i=1;i<=N;++i)
for(int j=1;j<=N;++j)
scanf("%d",&a[i][j]);
for(int i=1;i<=N;++i)
for(int j=1;j<=N;++j)
scanf("%d",&b[i][j]);
for(int i=1;i<=N;++i)
for(int j=1;j<=N;++j)
for(int k=1;k<=4;++k)
scanf("%d",&c[i][j][k]);
back(1,1);
printf("%d\n",maxim);
}