比赛 20120709 评测结果 AAAAAAAAAA
题目名称 磁性链 最终得分 100
用户昵称 SnowDancer 运行时间 0.010 s
代码语言 Pascal 内存使用 0.20 MiB
提交时间 2012-07-09 10:45:14
显示代码纯文本
var
  code:array[0..101] of longint;
  f:array[1..100,1..100] of longint;
  n,i,j,k,tot:longint;
function min(x,y:longint):longint;
  begin if x<y then exit(x) else exit(y); end;
begin
assign(input,'linka.in'); reset(input);
assign(output,'linka.out'); rewrite(output);
  readln(tot,n);  code[n+1]:=tot+1;
  for i:=1 to n do read(code[i]);
  for i:=1 to n do
    f[i,i]:=code[i+1]-code[i-1]-2;
  for i:=1 to n-1 do
    for j:=1 to n-i do begin
      f[j,i+j]:=min(f[j+1,i+j],f[j,i+j-1]);
      for k:=j+1 to i+j-1 do
        f[j,i+j]:=min(f[j,i+j],f[j,k-1]+f[k+1,i+j]);
      inc(f[j,i+j],code[j+i+1]-code[j-1]-2);
    end;
  writeln(f[1,n]);
close(input); close(output);
end.