- 能量项链
- 2014-01-03 16:47:21 @
var
a:array[0..110]of longint;
f:array[0..110,0..110]of longint;
i,j,k,p,n,max:longint;
procedure datain;
begin
readln(n);
for i:=1 to n do read(a[i]);
for i:=n+1 to 2*n-1 do a[i]:=a[i-n];
end;
begin
datain;
for i:=1 to n do
begin
for j:=1 to n-1 do
for k:=i to n-j do
begin
max:=0;
for p:=k to j+k do
if f[k,p]+f[p+1,j+k]+a[k]*a[p+1]*a[j+k]>max then max:=f[k,p]+f[p+1,j+k]+a[k]*a[p+1]*a[j+k];
f[k,j+k]:=max;
end;
end;
max:=0;
for i:=1 to n do
if f[i,i+n-1]>max then max:=f[i,i+n-1];
write(max);
end.
1 条评论
-
zhangzj2014 LV 7 @ 2014-12-13 15:54:11
为何要用四重循环?
i:2-->n
j:1-->2n
f[i,j]=max(f[k,j]+f[i-k,j+k]+a[j]·a[j+k]·a[j+i])
注: k:1-->i-1
- 1