比赛 |
NOIP2008集训模拟3 |
评测结果 |
AWWTWWWWWA |
题目名称 |
工作分配 |
最终得分 |
20 |
用户昵称 |
francis |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-11-12 11:07:31 |
显示代码纯文本
program divide;
const
fin='divide.in';
fou='divide.out';
max1=100000000000000000;
var
a:array[1..1001]of longint;
f:array[0..1001,0..1001]of int64;
min,max:array[0..1001,0..1001]of longint;
p,m,n,k,c,i,j:longint;
total:int64;
f1,f2:text;
procedure init;
begin
assign(f1,fin);
assign(f2,fou);
reset(f1); rewrite(f2);
read(f1,n,k,c);
if n>1000 then begin writeln(f2,1000000000); close(f1); close(f2); halt; end;
for i:=1 to n do
begin
read(f1,a[i]);
min[i,i]:=a[i];
max[i,i]:=a[i];
end;
for p:=2 to n do
for i:=1 to n-p+1 do
begin
j:=i+p-1;
if min[i,i]<min[i+1,j] then min[i,j]:=min[i,i] else min[i,j]:=min[i+1,j];
if max[i,i]>max[i+1,j] then max[i,j]:=max[i,i] else max[i,j]:=max[i+1,j];
readln(f1);
end;
if (n mod k)=0 then m:=n div k
else m:=(n div k)+1;
for i:=0 to n do
for j:=0 to m do
f[i,j]:=max1;
f[k,1]:=c+sqr(max[1,k]-min[1,k]); f[0,0]:=0;
end;
procedure main;
begin
for i:=k+1 to n do
for j:=1 to m do
begin
for p:=i-k downto (j-1)*k do
if f[i,j]>f[p,j-1]+c+sqr(max[p+1,i]-min[p+1,i])
then f[i,j]:=f[p,j-1]+c+sqr(max[p+1,i]-min[p+1,i])
end;
end;
procedure print;
begin
total:=max1;
for i:=1 to m do
if total>f[n,i] then total:=f[n,i];
if total=max1 then total:=0;
write(f2,total);
close(f1); close(f2);
end;
begin
init;
main;
print;
end.