为什么第九个点过不了啊?

var
t,n,m,ans:longint;
a,f,x,y:array[1..250005]of longint;
b:array[0..501,0..501]of longint;
procedure init;
var
i,j:longint;
begin
readln(n,m);
for i:=1 to n do
for j:=1 to m do
begin
read(t);
a[(i-1)*m+j]:=t;
x[(i-1)*m+j]:=i;
y[(i-1)*m+j]:=j;
b[i,j]:=(i-1)*m+j;
end;
end;
procedure change(var p,q:longint);
begin
t:=p; p:=q; q:=t;
end;
procedure qsort(l,r:longint);
var
i,j,k:longint;
begin
i:=l; j:=r; k:=a[(i+j)div 2];
repeat
while a[i]>k do inc(i);
while a[j]<k do dec(j);
if i<=j then begin
change(a[i],a[j]);
change(x[i],x[j]);
change(y[i],y[j]);
b[x[i],y[i]]:=i;
b[x[j],y[j]]:=j;
inc(i); dec(j);
end;
until i>j;
if i<r then qsort(i,r);
if j>l then qsort(l,j);
end;
procedure dp;
var
i,j:longint;
begin
for i:=1 to n*m do
begin
f[i]:=1;
if b[x[i],y[i]-1]<i then
if f[b[x[i],y[i]-1]]+1>f[i] then f[i]:=f[b[x[i],y[i]-1]]+1;
if b[x[i],y[i]+1]<i then
if f[b[x[i],y[i]+1]]+1>f[i] then f[i]:=f[b[x[i],y[i]+1]]+1;
if b[x[i]-1,y[i]]<i then
if f[b[x[i]-1,y[i]]]+1>f[i] then f[i]:=f[b[x[i]-1,y[i]]]+1;
if b[x[i]+1,y[i]]<i then
if f[b[x[i]+1,y[i]]]+1>f[i] then f[i]:=f[b[x[i]+1,y[i]]]+1;
if f[i]>ans then ans:=f[i];
end;
end;
begin
init;
qsort(1,n*m);
dp;
writeln(ans);
end.

2 条评论

  • @ 2016-12-14 13:11:11

    额呵嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿

  • @ 2013-06-08 19:15:07

    我第九个点也过不去。时间给卡了

  • 1

信息

ID
1011
难度
6
分类
动态规划 点击显示
标签
递交数
10384
已通过
2952
通过率
28%
被复制
29
上传者