比赛 |
NOIP2008集训模拟1 |
评测结果 |
WWAAWTWWWW |
题目名称 |
埃雷萨拉斯的宝藏 |
最终得分 |
20 |
用户昵称 |
E.M.B.E.R |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-11-10 11:17:20 |
显示代码纯文本
program EmberAsh;
const
dx:array[1..4]of integer=(0,1,0,-1);
dy:array[1..4]of integer=(1,0,-1,0);
type node=record
xx:longint;
yy:longint;
end;
var
a:array[1..50,1..50]of integer;//矩阵
b:array[1..2500]of longint;//受到的伤害
bb:array[1..50,1..50]of boolean;
f:array[1..50,1..50]of longint;//到(i,j)所能保存的最大生命值
tt:array[1..2500,1..2500]of node;//坐标
cost:array[1..2500]of longint;//对应上面的数值
head,tail:longint;
n,p,h,i,j,k,min,max:longint;
fin,fout:text;
procedure try(x,y,s,t:longint);
var
i,j,k,x1,y1,s1,t1:longint;
begin
if (x=n)and(y<=n) then
begin
for i:=1 to n do
if (f[1,i]>max)and(f[1,i]<>maxlongint)and(f[1,i]<>h) then
max:=f[1,i];
end
else
begin
for i:=1 to 4 do
begin
x1:=x+dx[i];y1:=y+dy[i];
if (x1<=n)and(y1<=n)and(x1>=1)and(y1>=1)and(f[x1,y1]>f[x,y])and(bb[x1,y1]=false) then
if (a[x1,y1]=t) then
begin
s1:=s;t1:=t;
if s1>0 then
begin
f[x1,y1]:=f[x,y];
bb[x1,y1]:=true;
try(x1,y1,s1,t1);
bb[x1,y1]:=false;
end;
end
else
begin
s1:=s-b[a[x1,y1]];
t1:=a[x1,y1];
if (s1>0)and(bb[x1,y1]=false) then
begin
f[x1,y1]:=s1;
bb[x1,y1]:=true;
try(x1,y1,s1,t1);
bb[x1,y1]:=false;
end;
end;
end;//不跳
for i:=1 to cost[a[x,y]] do
//if s>0 then
begin
x1:=tt[a[x,y],i].xx;
y1:=tt[a[x,y],i].yy;
if (f[x1,y1]<=f[x,y])and(bb[x1,y1]=false) then
begin
s1:=s;t1:=t;
bb[x1,y1]:=true;
f[x1,y1]:=s1;
try(x1,y1,s1,t1);
bb[x1,y1]:=false;
end;
end;
end;
end;//procedure
BEGIN
assign(fin,'eldrethalas.in');reset(fin);
assign(fout,'eldrethalas.out');rewrite(fout);
readln(fin,n,p,h);
for i:=1 to p do
readln(fin,b[i]);//伤害
for i:=1 to n do
for j:=1 to n do
begin
read(fin,a[i,j]);
inc(cost[a[i,j]]);
tt[a[i,j],cost[a[i,j]]].xx:=i;
tt[a[i,j],cost[a[i,j]]].yy:=j;
f[i,j]:=maxlongint;
end;
max:=0;
for i:=1 to n do//``````````````````i=1
begin
for j:=1 to n do
for k:=1 to n do
f[j,k]:=maxlongint;
f[1,i]:=h;
try(1,i,h,a[1,i]);//(1,i) 生命值为h 在a[1,i]上
end;
if max>0 then
writeln(fout,max)
else
writeln(fout,'NO');
close(fin);close(fout);
END.