program two;
const
maxn=1000;
maxm=2;
var
n:longint;
w:array [0..maxn] of longint;
d:array [0..maxn,0..maxn] of longint;
f:array [-1..maxn,-1..maxn,-1..maxm] of longint;
procedure init;
var
i,j:longint;
begin
fillchar(d,sizeof(d),100);
fillchar(f,sizeof(f),100);
readln(n);
for i:=n downto 1 do readln(w[i],d[i,i-1]);
for i:=0 to n-1 do for j:=i+2 to n do d[j,i]:=d[j-1,i]+d[j,j-1];
end;
function min(x,y:longint):longint;
begin
if x<y then exit(x) else exit(y);
end;
function dp(st,ed,build:longint):longint;
var
i,temp:longint;
begin
if f[st,ed,build]<f[-1,-1,-1] then exit(f[st,ed,build]);
for i:=0 to build do
begin
temp:=0;
if st<n then inc(temp,dp(st+1,ed,build));
inc(temp,d[st,ed]*w[st]);
f[st,ed,build]:=min(f[st,ed,build],temp);
end;
for i:=0 to build-1 do
begin
temp:=0;
if st<n then inc(temp,dp(st+1,st,build-1));
f[st,ed,build]:=min(f[st,ed,build],temp);
end;
exit(f[st,ed,build]);
end;
begin
init;
writeln(dp(0,0,2));
readln;
end.
有向直线2中值问题(two)[60分]
最新推荐文章于 2024-03-19 01:11:00 发布
程序两通过定义常量、变量、过程,并实现初始化和动态规划算法来解决特定问题。
1万+

被折叠的 条评论
为什么被折叠?



