Pagini recente » Cod sursa (job #1656802) | Cod sursa (job #1656197) | Cod sursa (job #2679881) | Cod sursa (job #1656957) | Cod sursa (job #396874)
Cod sursa(job #396874)
var i,n,j,k:longint;
min,x:int64;
d:array[0..505] of int64;
s:array[0..10003,0..10003] of int64;
bufin:array[0..65000] of byte;
begin
assign(input,'podm.in');
reset(input);
settextbuf(input,bufin);
assign(output,'podm.out');
rewrite(output);
readln(n);
for i:=1 to n+1 do read(d[i-1]);
for i:=1 to n-1 do
s[i,i+1]:=d[i-1]*d[i]*d[i+1];
for j:=2 to n-1 do begin
for i:=1 to n-j do begin
min:=999999999999999999;
for k:=i to i+j-1 do begin
x:=s[i,k]+s[k+1,i+j]+d[i-1]*d[k]*d[i+j];
if x<min then min:=x;
end;
s[i,i+j]:=min;
end;
end;
writeln(s[1,n]);
close(input);
close(output);
end.