发布网友 发布时间:2024-10-01 10:43
共1个回答
热心网友 时间:2024-12-06 13:40
状态转移方程是 f[i] := min(f[i - 1] + t[i], f[i - 2] + r[i - 1]); {i = 2 ~ n}追答const
maxn = 1000;
var i, j, n : longint;
f, t, r : array[0..maxn] of longint;
function min(a, b : longint) : longint;
begin if a < b then exit(a); exit(b); end;
begin
readln(n);
for i := 1 to n do read(t[i]);
for i := 1 to n - 1 do read(r[i]);
f[0] := 0; f[1] := t[1];
for i := 2 to n do
f[i] := min(f[i - 1] + t[i], f[i - 2] + r[i - 1]);
writeln(f[n]);
end.