比赛 |
NOIP2008集训模拟1 |
评测结果 |
ATWWWWTWWA |
题目名称 |
埃雷萨拉斯的宝藏 |
最终得分 |
20 |
用户昵称 |
zxc111 |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-11-10 10:47:03 |
显示代码纯文本
program ooo;
var
i,j,k,n,m,p,h,min:longint;
a:array[0..50,0..50] of longint;
c:array[0..2500] of boolean;
b:array[0..2500] of longint;
t:Text;
procedure oo(l,r,q:longint);
var
i,j,k:longint;
begin
if l=n then begin if min<q then min:=q;exit;end;
for i:=1 to n do
for j:=1 to n do
if a[i,j]=a[l,r] then
begin
if (c[a[i+1,j]]=false)and(i+1<=n)and(q-b[a[i+1,j]]>0) then
begin
c[a[i+1,j]]:=true;
oo(i+1,j,q-b[a[i+1,j]]);
c[a[i+1,j]]:=false;
end;
if (c[a[i-1,j]]=false)and(i>1)and(q-b[a[i-1,j]]>0) then
begin
c[a[i-1,j]]:=true;
oo(i-1,j,q-b[a[i-1,j]]);
c[a[i-1,j]]:=false;
end;
if (c[a[i,j+1]]=false)and(j+1<=n)and(q-b[a[i,j+1]]>0) then
begin
c[a[i,j+1]]:=true;
oo(i,j+1,q-b[a[i,j+1]]);
c[a[i,j+1]]:=false;
end;
if (c[a[i,j-1]]=false)and(j-1>0)and(q-b[a[i,j-1]]>0) then
begin
c[a[i,j-1]]:=true;
oo(i,j-1,q-b[a[i,j-1]]);
c[a[i,j-1]]:=false;
end;
end;
end;
begin
assign(t,'eldrethalas.in');
reset(t);
readln(t,n,p,h);
for i:=1 to p do
readln(t,b[i]);
for i:=1 to n do
begin
for j:=1 to n do
read(t,a[i,j]);
readln(t);
end;
close(t);
fillchar(c,sizeof(c),false);
min:=0;
for i:=1 to n do
begin
c[a[1,i]]:=true;
oo(1,i,h-b[a[1,i]]);
c[a[1,i]]:=false;
end;
assign(t,'eldrethalas.out');
rewrite(t);
if min=maxlongint then write(t,'NO') else write(t,min);
close(t);
end.