比赛 |
20101025 |
评测结果 |
AAWAAAAAAA |
题目名称 |
整理书本 |
最终得分 |
90 |
用户昵称 |
belong.zmx |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2010-10-25 20:37:54 |
显示代码纯文本
program book(input,output);
var
f1,f2:array[0..400,0..400]of longint;
i,j,k:longint;
n:longint;
a:Array[1..400]of longint;
function min(a,b:longint):longint;
begin
if a>b then min:=b else min:=a;
end;
begin
assign(input,'book.in');
reset(input);
readln(n);
for i:=1 to n do
begin
readln(k,j);
a[i]:=abs(k-j);
end;
close(input);
for i:=1 to n do
for j:=1 to n do
f1[i,j]:=999999;
for i:=1 to n do
begin
f1[i,i]:=0;
f2[i,i]:=a[i];
end;
for k:=1 to n do
for i:=1 to n-k+1 do
for j:=i to i+k-1 do
if f1[i,i+k-1]>f1[i,j]+f1[j+1,i+k-1]+f2[i,j]+f2[j+1,i+k-1] then
begin
f1[i,i+k-1]:=f1[i,j]+f1[j+1,i+k-1]+f2[i,j]+f2[j+1,i+k-1];
f2[i,i+k-1]:=f2[i,j]+f2[j+1,i+k-1];
end;
assign(output,'book.out');
rewrite(output);
writeln(f1[1,n]);
close(output);
end.