如果发现广告等破坏行为,请尽量将条目恢复到较早的版本而不是把相应内容直接删除,谢谢合作。
NOCOW:新手试练场
来自"NOCOW"
var f,m:array[0..31,0..31] of longint; a:array[1..30] of longint; ans,i,n:longint; procedure find(x,y:longint); var i:longint; begin if x=y then exit; if x>y then begin f[x,y]:=1; exit; end; if f[x,y]<>0 then exit; for i:=x to y do begin find(x,i-1); find(i+1,y); if a[i]+f[x,i-1]*f[i+1,y]>f[x,y] then begin f[x,y]:=f[x,i-1]*f[i+1,y]+a[i]; m[x,y]:=i; end; end; end; procedure outout(x,y:longint); begin write(m[x,y],' '); if x=y then exit; if x<m[x,y] then outout(x,m[x,y]-1); if m[x,y]<y then outout(m[x,y]+1,y); end; begin readln(n); for i:=1 to n do read(a[i]); for i:=1 to n do begin f[i,i]:=a[i]; m[i,i]:=i; end; find(1,n); writeln(f[1,n]); outout(1,n); end.

