比赛 暑假培训七 评测结果 AAAAAAWWWW
题目名称 石子合并 最终得分 60
用户昵称 elysian 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-07-24 17:37:32
显示代码纯文本
program cc;
var
g:array[1..100,1..100] of longint;
a:array[1..100] of longint;
n,s,i,j,k,min:longint;
f1,f2:text;

procedure init;
begin
assign(f1,'shizi.in');
reset(f1);
readln(f1,n);
for i:=1 to n do
read(f1,a[i]);

for i:=1 to n do
for j:=i to n do
begin
s:=0;
for k:=i to j do s:=s+a[k];
g[i,j]:=s;
g[j,i]:=s;
end;
end;

procedure main;
var
i,j,k:longint;
f:array[1..100,1..100] of integer;
min:longint;
begin
min:=maxlongint;
for i:=2 to n do
for j:=1 to n-i+1 do
begin
min:=f[i-1,j];
for k:=i-1 downto 1 do
if f[k,j]+f[i-k,j+k]<min then min:=f[k,j]+f[i-k,j+k];
f[i,j]:=g[j,i+j-1] +min;
end;

assign(f2,'shizi.out');
rewrite(f2);
writeln(f2,f[n,1]);

end;


begin

init;
main;
close(f1);
close(f2);
end.