2018.06.23【2018提高组】模拟C组
【NOIP2013模拟】刺杀大使 (Standard IO)
题目:
伊朗伊斯兰革命卫队(某恐怖组织)正在策划一起刺杀行动,他们的目标是沙特驻美大使朱拜尔。他们来到了沙特驻美使馆,准备完成此次刺杀,要进入使馆首先必须通过使馆前的防御迷阵。
迷阵一个由n*m个相同的小房间组成,每个房间与相邻四个房间之间有门可通行。在第n行的m个房间里有m个机关,这些机关必须全部被打开才可以进入大使馆。而第1行的m个房间有m扇向外开的门,是迷阵的入口。除了第1行和第n行的房间外,每个房间都被使馆的安保人员安装了激光杀伤装置,将会对进入房间的人造成一定的伤害。第i行第j列造成的伤害值为p[i][j](第1行和第n行的p值全部为0)。
现在伊斯兰革命卫队打算以最小伤害代价进入迷阵,打开全部机关,显然,他们可以选择任意多的人从任意的门进入,但必须到达第n行的每个房间。一个士兵受到的伤害值为他到达某个机关的路径上所有房间的伤害值中的最大值,整个部队受到的伤害值为所有士兵的伤害值中的最大值。现在,这个恐怖组织掌握了迷阵的情况,他们需要提前知道怎么安排士兵的行进路线可以使得整个部队的伤害值最小。
数据分析
Input
第一行有两个整数n,m,表示迷阵的大小。
接下来有n行,每行m个数,第i行第j列的数表示p[i][j]。
Output
输出一个数,表示最小伤害代价。
Sample Input
4 2
0 0
3 5
2 4
0 0
Sample Output
3
Data Constraint
50%的数据,n,m<=100
100%的数据,n,m<=1000, p[i][j]<=1000
50分思路记忆化深搜
var
i,j,m,k,n,max:longint;
a,f:array[0..1001,0..1001] of longint;
function check(a,b:longint):boolean;
begin
if (a>=1) and (a<=n) and (b>=1) and (b<=m) then exit(true);
exit(false);
end;
procedure dfs(x,y,tot:longint);
var
i,j,dq:longint;
begin
if a[x,y]>tot then dq:=a[x,y]
else dq:=tot;
if f[x,y]=0 then f[x,y]:=dq
else begin
if dq<f[x,y] then f[x,y]:=dq
else exit;
end;
if x=n then begin
if f[x,y]<max then max:=f[x,y];
exit;
end;
if check(x+1,y) then dfs(x+1,y,f[x,y]);
if check(x,y+1) then dfs(x,y+1,f[x,y]);
if check(x,y-1) then dfs(x,y-1,f[x,y]);
end;
begin
readln(n,m);
for i:=1 to n do
begin
for j:=1 to m do
begin
read(a[i,j]);
if (i=1) or (i=2) then f[i,j]:=a[i,j];
end;
readln;
end;
max:=maxlongint;
for i:=1 to m do
dfs(3,i,f[2,i]);
writeln(max);
end.