大神们求助啊

堆排加dp,为啥是错的?
测试数据 #0: WrongAnswer, time = 140 ms, mem = 20448 KiB, score = 0
测试数据 #1: WrongAnswer, time = 31 ms, mem = 20448 KiB, score = 0
测试数据 #2: WrongAnswer, time = 46 ms, mem = 20448 KiB, score = 0
测试数据 #3: WrongAnswer, time = 15 ms, mem = 20448 KiB, score = 0
测试数据 #4: WrongAnswer, time = 93 ms, mem = 20448 KiB, score = 0
测试数据 #5: WrongAnswer, time = 15 ms, mem = 20448 KiB, score = 0
测试数据 #6: WrongAnswer, time = 0 ms, mem = 20448 KiB, score = 0
测试数据 #7: WrongAnswer, time = 62 ms, mem = 20448 KiB, score = 0
测试数据 #8: Accepted, time = 3 ms, mem = 20448 KiB, score = 10
测试数据 #9: Accepted, time = 62 ms, mem = 20452 KiB, score = 10
WrongAnswer, time = 467 ms, mem = 20452 KiB, score = 20
代码
program p1011;
const move:array[1..4,1..2] of longint=((0,1),(0,-1),(-1,0),(1,0));
var x,y,h:array[-1..1000002] of longint;
hh,f:array[-1..1002,-1..1002] of longint;
nn,m,n,i,j,ans:longint;
//
function max(a,b:longint):longint;
begin
if a>b then exit(a)
else exit(b);
end;
//
procedure swap(a,b:longint);
var k:longint;
begin
k:=x[a];x[a]:=x[b];x[b]:=k;
k:=y[a];y[a]:=y[b];y[b]:=k;
k:=h[a];h[a]:=h[b];h[b]:=k;
end;
//
procedure fixdui(i,r:longint);
var p1,p2:longint;
begin
p1:=i;p2:=p1 shl 1;
while ((p2<=r) and (h[p2]<h[p1])) or ((p2+1<=r) and (h[p2+1]<h[p1])) do
begin
if (p2+1<=r) and (h[p2+1]<h[p2]) then inc(p2);
swap(p1,p2);
p1:=p2;p2:=p1 shl 1;
end;
end;
//
begin
read(m,nn);
for i:=0 to m-1 do
for j:=1 to nn do
begin
x[i*nn+j]:=i+1;y[i*nn+j]:=j;read(h[i*nn+j]);
hh[i+1,j]:=h[i*nn+j];
end;
n:=nn*m;
for i:=n shr 1 downto 1 do fixdui(i,n);
for i:=1 to n-1 do
begin
swap(1,n-i+1);
fixdui(1,n-i);
end;
f[x[1],y[1]]:=1;
for i:=2 to n do
for j:=1 to 4 do
if (hh[x[i]+move[j,1],y[i]+move[j,2]]>hh[x[i],y[i]]) then
f[x[i],y[i]]:=max(f[x[i],y[i]],1+f[x[i]+move[j,1],y[i]+move[j,2]]);
for i:=1 to m do
for j:=1 to nn do ans:=max(ans,f[i,j]);
write(ans);
end.

0 条评论

目前还没有评论...

信息

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