不多说了,直接上代码
var n,m,i,j,k,x,y,l,r,t:longint; f,g:array[0..100,0..100]of longint; a:array[0..100]of longint; function max(a,b:longint):longint; begin if a>b then exit(a) else exit(b); end; procedure dfs(l,r:longint); var i,j:longint; b:boolean; begin if l<=r then begin write(g[l,r],‘ ‘); dfs(l,g[l,r]-1); dfs(g[l,r]+1,r); end else exit; 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]; f[i,i-1]:=1; g[i,i]:=i; end; for i:=n-1 downto 1 do for j:=i+1 to n do for k:=i to j do begin if f[i,j]<f[i,k-1]*f[k+1,j]+a[k] then begin f[i,j]:=f[i,k-1]*f[k+1,j]+a[k]; g[i,j]:=k; end; end; writeln(f[1,n]); dfs(1,n); end.
喜欢就收藏一下,vic私人qq:1064864324,加我一起讨论问题,一起进步^-^
时间: 2024-10-24 23:55:02