/ Vijos / 讨论 / 过河 /

求问下为什么超时啊。。

program p1002;
var
f:array[0..200000] of integer;
m:array[1..100] of longint;
i,j:longint;
S,T,L,N,jump,temp,cha,min:longint;
sf:boolean;
begin
readln(L);
readln(S,T,N);
for i:=1 to n do begin read(m[i]); end;
jump:=n;
while jump>1 do begin
jump:=jump div 2;
repeat
sf:=true;
for i:=1 to n-jump do
if m[i]>m[i+jump] then begin
temp:=m[i];
m[i]:=m[i+jump];
m[i+jump]:=temp;
sf:=false;
end;
until sf;
end; //希尔法
l:=m[n]+t;
for i:=1 to n-1 do begin
cha:=m[i+1]-m[i];
if cha>105 then begin
l:=(l-cha)+105;
for j:=i+1 to n do
m[j]:=(m[j]-cha)+105;
end;
end; //压缩
for i:=1 to l do begin f[i]:=0; end;
f[0]:=0;
for i:=1 to n do begin f[m[i]]:=1; end;
for i:=1 to l do begin
min:=300;
for j:=s to t do begin
if (f[i-j]<min) and ((i-j)>=0) then min:=f[i-j];
end;
f[i]:=f[i]+min;//DP
end;
writeln(f[l]);
end.

1 条评论

  • 1

信息

ID
1002
难度
7
分类
动态规划 点击显示
标签
递交数
25264
已通过
4390
通过率
17%
被复制
76
上传者