比赛 |
NOIP2008集训模拟3 |
评测结果 |
AWWWETTTTA |
题目名称 |
工作分配 |
最终得分 |
20 |
用户昵称 |
苏轼 |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-11-12 11:24:53 |
显示代码纯文本
program cch(input,output);
var
i,n,k,c,j,maxf,minf,q:longint;
ans:int64;
data:array[1..100000] of longint;
max,min:array[1..1000,1..1000] of longint;
f:array[0..1000,0..1000] of int64;
begin
assign(input,'divide.in');
assign(output,'divide.out');
reset(input);
rewrite(output);
readln(n,k,c);
for i:=1 to n do read(data[i]);
for i:=1 to n do
begin
maxf:=data[i]; minf:=data[i];
for j:=i+1 to n do
begin
if maxf<data[j] then maxf:=data[j];
if minf>data[j] then minf:=data[j];
max[i,j]:=maxf; min[i,j]:=minf;
end;
end;
f[0,0]:=0;
for i:=1 to n do
for j:=1 to (i div k) do
begin
f[i,j]:=100000000;
for q:=0 to (j-1) div k do
if f[i,j]>f[q,j-1]+sqr(max[q+1,i]-min[q+1,i])+c then
f[i,j]:=f[q,j-1]+sqr(max[q+1,i]-min[q+1,i])+c;
end;
ans:=1000000000;
for i:=1 to n div k do
if ans>f[n,i] then ans:=f[n,i];
write(ans);
close(input);
close(output);
end.