记录编号 |
3419 |
评测结果 |
AAAAAAAAAA |
题目名称 |
石子合并 |
最终得分 |
100 |
用户昵称 |
苏轼 |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.026 s |
提交时间 |
2008-10-06 21:51:54 |
内存使用 |
0.19 MiB |
显示代码纯文本
program cch(input,output);
var
i,j,n,k:integer;
f,a:array[1..100,1..100] of longint;
data:array[1..100] of longint;
function min(x,y:longint):longint;
begin
if x<y then exit(x)
else exit(y);
end;
begin
assign(input,'shizi.in');
assign(output,'shizi.out');
reset(input);
rewrite(output);
readln(n);
for i:=1 to n do readln(data[i]);
for i:=1 to n do
for j:=i to n do
begin
a[i,j]:=0;
for k:=i to j do
inc(a[i,j],data[k]);
end;
for i:=1 to n do
for j:=1 to n do
f[i,j]:=maxlongint;
for i:=1 to n do f[i,i]:=0;
for i:=1 to n-1 do
for j:=1 to n do
for k:=j to i+j-1 do
f[j,i+j]:=min(f[j,j+i],f[j,k]+f[k+1,j+i]+a[j,j+i]);
write(f[1,n]);
close(input);
close(output);
end.