南海乡村俱乐部:Leapcow(leapcow,pas)

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/27 21:19:57
坐标轴上有一个点,要从坐标0跳到坐标E,5〈=E〈=40000。每次跳有L(3〈=L〈=50)种选择:即向右移动长度为1到L中任意一个整数。但是坐标轴上有B(1〈=B〈=500)个点是不能去的。问从0到E至少要跳几次。输入保证有解。
输入 leapcow.in
第一行是E、L、B。
接下来有B行,每行一个整数,表示不能跳到的坐标。
输出 leapcow.out
最少要跳几次。

var min,e,l,b,sum,i,j:longint;
a:array[1..40000]of boolean;
procedure tiao(s:longint);
var i:longint;
begin
for i:=1 to l do begin
if (a[s+i]=false)or(s+i>e) then continue
else if (a[s+i]=true)and(not(s+i=e)) then begin
sum:=sum+1;
tiao(s+i);
end
else if s+i=e then if sum<min then min:=sum;
end;
end;
begin
assign(input,'leapcow.in');reset(input);
assign(output,'leapcow.out');rewrite(output);
fillchar(a,sizeof(a),true);
min:=maxlongint;
readln(e,l,b);
for i:=1 to b do begin
readln(j);
a[j]:=false;
end;
tiao(0);
writeln(min+1);
close(input);close(output);
end.