| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
给你我的代码吧In Reply To:今天郁闷了,这题都TLE,大牛帮忙优化一下…… Posted by:JiangLY at 2005-04-29 17:48:48 Program PKU1088;
var
map:array[0..101,0..101] of integer;
ans:array[1..100,1..100] of integer;
calc:array[0..101,0..101] of boolean;
i,j,m,n,w,h,max,t:integer;
function f(x,y:integer):integer;
var
tmp:integer;
begin
f:=0;
if x*y=0 then exit;
if x*y<0 then exit;
if x>w then exit;
if y>h then exit;
if calc[x,y] then
begin
f:=ans[x,y];
exit;
end;
if map[x-1,y]<map[x,y] then
begin
tmp:=f(x-1,y)+1;
if tmp>ans[x,y] then ans[x,y]:=tmp;
end;
if map[x+1,y]<map[x,y] then
begin
tmp:=f(x+1,y)+1;
if tmp>ans[x,y] then ans[x,y]:=tmp;
end;
if map[x,y-1]<map[x,y] then
begin
tmp:=f(x,y-1)+1;
if tmp>ans[x,y] then ans[x,y]:=tmp;
end;
if map[x,y+1]<map[x,y] then
begin
tmp:=f(x,y+1)+1;
if tmp>ans[x,y] then ans[x,y]:=tmp;
end;
calc[x,y]:=true;
if ans[x,y]=0 then ans[x,y]:=1;
f:=ans[x,y];
end;
begin
while not eoln do
begin
fillchar (map,sizeof(map),0);
fillchar (ans,sizeof(ans),0);
readln (w,h);
for i:=1 to w do
begin
for j:=1 to h do
read (map[i,j]);
readln;
end;
max:=0;
fillchar (calc,sizeof(calc),false);
for i:=1 to w do
for j:=1 to h do
begin
if ans[i,j]=0 then ans[i,j]:=1;
t:=f(i,j);
if t>max then max:=t;
end;
writeln (max);
end;
end.
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator