比赛 |
NOIP2008集训模拟1 |
评测结果 |
AAAAAAAAAA |
题目名称 |
埃雷萨拉斯的宝藏 |
最终得分 |
100 |
用户昵称 |
francis |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-11-10 11:24:58 |
显示代码纯文本
program eldrethalas;
const
fin='eldrethalas.in';
fou='eldrethalas.out';
max=300000000;
var
a:array[1..51,1..51]of longint;
w,d:array[0..2600]of longint;
min,i,j,n,p,h:longint;
f1,f2:text;
procedure init;
begin
assign(f1,fin);
assign(f2,fou);
reset(f1); rewrite(f2);
read(f1,n,p,h);
for i:=1 to p do
begin
read(f1,w[i]);
d[i]:=max;
end;
d[0]:=max;
for i:=1 to n do
for j:=1 to n do
read(f1,a[i,j]);
for i:=1 to n do
d[a[1,i]]:=w[a[1,i]];
end;
procedure main;
begin
for i:=2 to n do
begin
for j:=1 to n do
if d[a[i,j]]>d[a[i-1,j]]+w[a[i,j]] then d[a[i,j]]:=d[a[i-1,j]]+w[a[i,j]];
for j:=1 to n do
if d[a[i,j]]>d[a[i+1,j]]+w[a[i,j]] then d[a[i,j]]:=d[a[i+1,j]]+w[a[i,j]];
for j:=2 to n do
if d[a[i,j]]>d[a[i,j-1]]+w[a[i,j]] then d[a[i,j]]:=d[a[i,j-1]]+w[a[i,j]];
for j:=n-1 downto 1 do
if d[a[i,j]]>d[a[i,j+1]]+w[a[i,j]] then d[a[i,j]]:=d[a[i,j+1]]+w[a[i,j]];
end;
end;
procedure print;
begin
min:=max;
for i:=1 to n do
if min>d[a[n,i]] then min:=d[a[n,i]];
h:=h-min;
if h<=0 then write(f2,'NO') else write(f2,h);
close(f1); close(f2);
end;
begin
init;
main;
print;
end.