比赛 |
NOIP2008集训模拟3 |
评测结果 |
C |
题目名称 |
工作分配 |
最终得分 |
0 |
用户昵称 |
lc |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-11-12 10:34:48 |
显示代码纯文本
program divide;
const
maxn=1000;
var
n,m,k,c:longint;
f:array[0..maxn,1..maxn] of int64;
gmax,gmin:array[1..maxn,1..maxn] of longint;
a:array[1..maxn*10] of longint;
function max(a,b,c:longint):longint;
begin
if a>b then max:=a else max:=b;
if c>max then max:=c;
end;
function min(a,b,c:longint):longint;
begin
if a<b then min:=a else min:=b;
if c<min then min:=c;
end;
procedure init;
var
i,j:integer;
begin
readln(n,k,c); m:=n div k;
for i:=1 to n do read(a[i]);
for i:=1 to n do
begin
gmax[i,i]:=a[i];
gmin[i,i]:=a[i];
end;
for i:=n-1 downto 1 do
for j:=i+1 to n do
begin
gmax[i,j]:=max(gmax[i,j],gmax[i+1,j],a[i]);
gmax[i,j]:=max(gmax[i,j],gmax[i,j-1],a[j]);
gmin[i,j]:=maxlongint;
gmin[i,j]:=min(gmin[i,j],gmin[i+1,j],a[i]);
gmin[i,j]:=min(gmin[i,j],gmin[i,j-1],a[j]);
end;
end;
procedure main;
var
i,j,p:longint;
tm,ans:int64;
begin
for i:=1 to n do
f[i,1]:=sqr(gmax[1,i]-gmin[1,i])+c;
for j:=2 to m do
for i:=j*k to n do
begin
f[i,j]:=maxlongint;
for p:=(j-1)*k to i-k do
begin
tm:=f[p,j-1]+sqr(gmax[p+1,i]-gmin[p+1,i])+c;
if tm<f[i,j]
then f[i,j]:=tm;
end;
end;
ans:=f[n,1];
for i :=2 to m do
if f[n,i]<ans then ans:=f[n,i];
writeln(ans);
end;
begin
assign(input,'divide.in');
assign(output,'divide.out');
reset(input); rewrite(output);
init;
main;
close(input); close(output);
end.