请教高手们一道编程题

2025-01-03 16:44:05
推荐回答(3个)
回答1:

OI的题吧

我觉得用动态规划做就可以了

从第一点开始, 记录到达每一个点所需的最少步数

类似于求最长递增或递减序列问题:)

回答2:

不会

回答3:

Program p1002;
Var L,s,t,m:longint;
a:array[1..102] of longint;
f:array [0..10000] of 0..1;

Procedure init;
var i,j,x,y,z:longint;
begin
readln(L);
readln(s,t,m);
fillchar(f,sizeof(f),0);
if t>s then begin
for i:=1 to m do read(a[i]);
readln;
for i:=1 to m do
for j:=i+1 to m do
if a[i]>a[j] then begin x:=a[i]; a[i]:=a[j]; a[j]:=x; end;
y:=0; z:=0;
for i:=1 to m do begin
a[i]:=a[i]-z;
if a[i]-y>100 then begin
z:=z+a[i]-y-100;
a[i]:=y+100;
end;
y:=a[i];
f[y]:=1;
end;
L:=L-z;
if L-a[m]>100 then L:=a[m]+100;
end else
begin
z:=0;
for i:=1 to m do begin
read(x);
if (x mod s)=0 then z:=z+1;
end;
readln;
writeln(z);
close(input);
close(output);
halt;
end;
end;

Procedure find;
var i,j,u:longint;
w:array [0..10000] of byte;
begin
fillchar(w,sizeof(w),0);
for i:=L downto 0 do begin
u:=200;
for j:=s to t do
if (w[i+j] w[i]:=u+f[i];
end;
writeln(w[0]);
end;

Begin
assign(input,'input.txt'); reset(input);
assign(output,'output.txt'); rewrite(output);
init;
find;
close(input);
close(output);
End.