比赛 20101025 评测结果 AAAAAAAAAA
题目名称 整理书本 最终得分 100
用户昵称 ZhouZn1 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-10-25 20:21:40
显示代码纯文本
program zzn;
var
        k,i,j,n,x,y,l,max:longint;
        f:array[1..400,1..400]of longint;
        w:array[0..400]of longint;
function sum(x,y:integer):longint;
begin
    exit(w[y]-w[x-1]);
end;
procedure init;
begin
        assign(input,'book.in');
        reset(input);
        assign(output,'book.out');
        rewrite(output);
        readln(n);
        w[0]:=0;
        for i:=1 to n do
         begin
             readln(x,y);
             w[i]:=w[i-1]+x-y;
         end;
       for i:=1 to 400 do
        for j:=1 to 400 do  f[i,j]:=maxlongint shr 1;
       for i:=1 to n do
        f[i,i]:=0;
end;
procedure closef;
begin
        close(input);
        close(output);
end;

procedure main;
begin
        for i:=n-1 downto 1 do
         for j:=1 to i do
          begin
              l:=n-i+1;
              max:=j+l-1;
              for k:=j to max-1 do
               begin
                 if f[j,max]>f[j,k]+f[k+1,max]+sum(j,max) then
                  f[j,max]:=f[j,k]+f[k+1,max]+sum(j,max);
               end;
          end;
        writeln(f[1,n]);
end;
begin
        init;
       main;
        closef;
end.