var
f:array[0..2000,0..2000] of longint;
a,b:array[0..2000] of longint;
n,m,i,j,k,l:longint;
function min(x,y:longint):longint;
begin
if x<y then exit(x);
exit(y);
end;
begin
readln(n,m);
for i:=1 to n do read(a[n-i+1]);
for i:=1 to m do read(b[m-i+1]);
for i:=1 to n do dec(a[i]);
for i:=1 to m do dec(b[i]);
fillchar(f,sizeof(f),120);
f[0,0]:=0;
for i:=1 to n do begin
for j:=1 to m do begin
f[i,j]:=min(f[i-1,j-1],min(f[i-1,j],f[i,j-1]))+a[i]*b[j];
end;
end;
writeln(f[n,m]);
end.
这是AC的代码
var
f:array[1..2001,1..2001]of longint;
a,b:array[1..1000]of longint;
i,j,m,n,k:longint;
function min(x,y:longint):longint;
begin
if x<y then exit(x);
exit(y);
end;
begin
readln(n,m);
for i:=1 to n do
begin
read(a[i]);
a[i]:=a[i]-1;
end;
for i:=1 to m do
begin
read(b[i]);
b[i]:=b[i]-1;
end;
for i:=1 to n+1 do
begin
f[i,m]:=maxlongint;
f[i,m+1]:=maxlongint;
end;
for j:=1 to m+1 do
begin
f[n,j]:=maxlongint;
f[n+1,j]:=maxlongint;
end;
f[n+1,m+1]:=0;
for i:=n downto 1 do
for j:=m downto 1 do
f[i,j]:=min(f[i,j],min(f[i+1,j+1],f[i+1,j]))+a[i]*b[j];
writeln(f[1,1]);
end.
这是我63分的代码,但是我的超时了,为什么 题号是P1846