比赛 |
NOIP2008集训模拟1 |
评测结果 |
ATWAAAAAWW |
题目名称 |
埃雷萨拉斯的宝藏 |
最终得分 |
60 |
用户昵称 |
苏轼 |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-11-10 11:14:20 |
显示代码纯文本
program cch(input,output);
const
xx:array[1..4] of integer=(-1,0,1,0);
yy:array[1..4] of integer=(0,1,0,-1);
var
a:array[1..2500] of longint;
map:array[1..50,1..50] of integer;
f:array[1..50,1..50] of longint;
h,p,n,i,j,k,q,x1,y1,ans:longint;
flag:boolean;
begin
assign(input,'eldrethalas.in');
assign(output,'eldrethalas.out');
reset(input);
rewrite(output);
readln(n,p,h);
for i:=1 to p do readln(a[i]);
for i:=1 to n do
for j:=1 to n do read(map[i,j]);
for i:=1 to n do
for j:=1 to n do
f[i,j]:=-1;
for i:=1 to n do f[1,i]:=h-a[map[1,i]];
flag:=true;
while flag do
begin
flag:=false;
for i:=1 to n do
for j:=1 to n do
begin
for k:=1 to n do
for q:=1 to n do
if (f[i,j]<f[k,q])and(map[i,j]=map[k,q]) then
begin
f[i,j]:=f[k,q];
flag:=true;
end;
for k:=1 to 4 do
begin
x1:=i+xx[k]; y1:=j+yy[k];
if (x1>=1)and(x1<=n)and(y1>=1)and(y1<=n) then
if (f[i,j]<f[x1,y1]-a[map[i,j]])and(map[i,j]<>map[x1,y1]) then
begin
f[i,j]:=f[x1,y1]-a[map[i,j]];
flag:=true;
end;
end;
end;
end;
ans:=0;
for i:=1 to n do
if f[n,i]>ans then ans:=f[n,i];
if f[n,n]>=0 then write(ans)
else write('NO');
close(input);
close(output);
end.