why

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 条评论

  • 1

信息

ID
1242
难度
4
分类
其他 点击显示
标签
递交数
1355
已通过
621
通过率
46%
被复制
4
上传者