比赛 NOIP2008集训模拟3 评测结果 AWWWTTTTTW
题目名称 工作分配 最终得分 10
用户昵称 E.M.B.E.R 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-11-12 10:42:12
显示代码纯文本
program EmberAsh;
var
i,j,k,n,m,kk,c:longint;
a:array[1..10000]of longint;
t:array[0..10000,0..1000]of longint;
f:array[0..10000,0..1000]of longint;
fin,fout:text;

procedure qsort(l,r: longint);
  var
 i,j,x,y: longint;
  begin
 i:=l;
 j:=r;
 x:=a[(l+r) div 2];
 repeat
   while a[i]<x do
inc(i);
   while x<a[j] do
dec(j);
   if not(i>j) then
 begin
y:=a[i];
a[i]:=a[j];
a[j]:=y;
inc(i);
j:=j-1;
 end;
 until i>j;
 if l<j then
   qsort(l,j);
 if i<r then
   qsort(i,r);
  end;

BEGIN
assign(fin,'divide.in');reset(fin);
assign(fout,'divide.out');rewrite(fout);
readln(fin,n,kk,c);
for i:=1 to n do
  read(fin,a[i]);
qsort(1,n);
m:=n div kk;//工人数   好像就是这样算的吧...(- -)
for i:=1 to n do
  for j:=i to n do
    t[i,j]:=c+(a[j]-a[i])*(a[j]-a[i]);
for i:=1 to n do
  f[i,1]:=c+(a[i]-a[1])*(a[i]-a[1]);
for i:=1 to n do
  for j:=2 to m do
    for k:=1 to i-1 do
      if k>=kk then
      if (f[k,j-1]+t[k+1,i]<f[i,j])or(f[i,j]=0) then
        f[i,j]:=f[k,j-1]+t[k+1,i];
c:=maxlongint;
for i:=1 to m do
  if f[n,i]<c then
    c:=f[n,i];
writeln(fout,c);
close(fin);close(fout);
END.