- 邮局问题
- 2012-08-07 18:04:53 @
program ex2;
var a:array[0..10000] of longint;
v,f:array[0..1000,0..1000] of longint;
i,j,n,m,k,l:longint;
begin
assign(input,'w2.in');
reset(input);
readln(m,n);
for i:=1 to m do read(a[i]);
for i:=1 to m do
for j:=1 to m do
for k:=i to j do
v:=v+abs(a[k]-a[(i+j) div 2]);
fillchar(f,sizeof(f),$7f);
for i:=1 to n do
begin
f:=v[1,i];
f:=0;
end;
for i:=2 to n do
for j:=1 to m do
for k:=1 to j do
if f[j,i]>f[k,i-1]+v[k+1,j] then
f[j,i]:=f[k,i-1]+v[k+1,j];
writeln(f[m,n]);
close(input);
end.
1 条评论
-
王昱炜 LV 4 @ 2012-08-07 18:56:45
也许吧
或许是这样的
- 1