记录编号 | 13129 | 评测结果 | AAAAAAAAAA | ||
---|---|---|---|---|---|
题目名称 | 384.筷子 | 最终得分 | 100 | ||
用户昵称 | 是否通过 | 通过 | |||
代码语言 | Pascal | 运行时间 | 0.022 s | ||
提交时间 | 2009-09-28 19:47:43 | 内存使用 | 0.15 MiB | ||
Program chop; Type sc=array [0..100,0..100] of longint; sc1=array [1..100] of longint; Var s:sc; a:sc1; i,j,p:longint; n,m,k,temp,min,temp1:longint; Begin assign(input,'chop.in'); assign(output,'chop.out'); reset(input); rewrite(output); readln(n,k); for i:=1 to n do read(a[i]); for i:=1 to (n-1) do begin for j:=(i+1) to n do begin if a[i]>a[j] then begin temp:=a[j]; a[j]:=a[i]; a[i]:=temp; end; end; end; k:=k+3; if (n div 2)<k then writeln('-1') else begin for i:=0 to 100 do for j:=1 to 100 do s[i,j]:=9999999; for i:=1 to n do begin for j:=1 to k do begin s[i,j]:=s[i-1,j]; for p:=1 to (i-1) do begin temp:=s[p-1,j-1]+(a[p]-a[i])*(a[p]-a[i]); if temp<s[i,j] then s[i,j]:=temp; end; end; end; writeln(s[n,k]); end; close(input); close(output); End.