1 条题解

  • 0
    @ 2021-6-14 23:29:35

    Pascal :

    var
       n,i,l,j,k,ans:longint;max:int64;
       a,b:array[0..100]of int64;
       f,root:array[0..100,0..100]of int64;
    procedure dfs(l,r:longint);
    begin
     if l>r then exit;
     inc(ans);
     b[ans]:=root[l,r];
     dfs(l,root[l,r]-1);
     dfs(root[l,r]+1,r);
    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];root[i,i]:=i;end;
     for i:=1 to n do f[i,i-1]:=1;
     for l:=1 to n-1 do
      begin
       for i:=1 to n-l do
        begin
         j:=i+l;
         max:=0;
         for k:=i to j do if f[i,k-1]*f[k+1,j]+a[k]>f[i,j]
          then begin f[i,j]:=f[i,k-1]*f[k+1,j]+a[k];root[i,j]:=k;end;
        end;
      end;
     writeln(f[1,n]);
     fillchar(b,sizeof(b),0);
     ans:=0;
     dfs(1,n);
     for i:=1 to ans-1 do write(b[i],' ');
     writeln(b[ans]);
    end.
    
    • 1

    信息

    ID
    228
    时间
    1000ms
    内存
    125MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者