比赛 20120712 评测结果 EEEEEEEEEE
题目名称 爆炸化合物 最终得分 0
用户昵称 SnowDancer 运行时间 0.000 s
代码语言 Pascal 内存使用 0.18 MiB
提交时间 2012-07-12 11:39:36
显示代码纯文本
program hike_DFS;
const
  dx:array[1..4] of longint=(0,1,0,-1);
  dy:array[1..4] of longint=(1,0,-1,0);
var
  n,i,j,k,l,m,ans:longint;
  map:array[1..60,1..60] of longint;
  visit:array[1..60,1..60] of boolean;
function max(x,y:longint):longint;
  begin if x>y then exit(x) else exit(y); end;
procedure search(x,y,flag,step:longint);
  var
    i,xp,yp:longint;
  begin
    visit[x,y]:=true;
    if step>ans then ans:=step;
    for i:=1 to 4 do begin
      xp:=x+dx[i];yp:=y+dy[i];
      if (xp<1) or (xp>n) or (yp<1) or (yp>m) then continue;
      if visit[xp,yp] then continue;
      if (flag=0) and (map[xp,yp]>map[x,y]) then begin
        search(xp,yp,0,step+1);
        search(xp,yp,1,step+1);
      end;
      if (flag=1) and (map[xp,yp]<map[x,y]) then begin
        search(xp,yp,1,step+1);
      end;
    end;
    visit[x,y]:=false;
  end;
begin
assign(input,'hike.in');reset(input);
assign(output,'hike.out');rewrite(output);
  readln(n,m);
  for i:=1 to n do
    for j:=1 to m do
      read(map[i,j]);
  for i:=1 to n do
    for j:=1 to m do
      search(i,j,0,1);
  writeln(ans);
close(input); close(output);
end.