记录编号 13201 评测结果 AAAAAAAAAA
题目名称 筷子 最终得分 100
用户昵称 GravatarAchilles 是否通过 通过
代码语言 Pascal 运行时间 0.005 s
提交时间 2009-09-29 20:04:01 内存使用 0.15 MiB
显示代码纯文本
program chop;
var
  i,j,k,n:longint;
  num:array[0..100]of longint;
  sz:array[0..100,0..100]of longint;
begin
  assign(input,'chop.in');
  assign(output,'chop.out');
  reset(input);
  rewrite(output);
  readln(n,k);
  for i:=1 to n do
    read(num[i]);
  for i:=1 to n-1 do
    for j:=i+1 to n do
      if num[i]>num[j] then begin
        num[0]:=num[i];
        num[i]:=num[j];
        num[j]:=num[0];
      end;
  k:=k+3;
  if n<k*2 then begin
    writeln(-1);
  end
  else begin
    for i:=0 to 100 do
      for j:=0 to 100 do
        sz[i,j]:=2000000000;
    for i:=0 to 100 do
    begin
      sz[1,i]:=0;
      sz[0,i]:=0;
    end;
    for i:=0 to 100 do
      for j:=0 to 100 do
        if i<j*2 then sz[i,j]:=2000000000;
    for i:=2 to n do
      for j:=1 to k do
        if i>=j*2 then begin
          sz[i,j]:=sz[i-2,j-1]+sqr(num[i]-num[i-1]);
          if sz[i-1,j]<sz[i,j] then sz[i,j]:=sz[i-1,j];
        end
        else sz[i,j]:=2000000000;
    writeln(sz[n,k]);
  end;
  close(input);
  close(output);
end.