标签:
var i,j,k,n,min:longint; sum,fmin:array [-10..200,-10..200]of longint; num:array[-10..200]of longint; begin readln(n); for i:=1 to n do begin read(num[i]); sum[i,1]:=num[i]; fmin[i,1]:=0; end; for j:=2 to n do for i:=1 to n-j+1 do sum[i,j]:=num[i]+sum[i+1,j-1]; for j:=2 to n do for i:=1 to n-j+1 do begin fmin[i,j]:=maxlongint; for k:=1 to j-1 do if (fmin[i,k]+fmin[k+i,j-k]+sum[i,j])>fmin[i,j] then fmin[i,j]:=fmin[i,k]+fmin[k+i,j-k]+sum[i,j]; end; min:=fmin[1,n]; writeln(min); end.
标签:
原文地址:http://www.cnblogs.com/songer/p/4847274.html