1 条题解

  • 0
    @ 2021-6-15 1:39:07

    C++ :

    #include <iostream>  
    using namespace std;  
    int n,e=0;  
    int a[111*2];  
    int dp[111*2][111*2];  
    int main()  
    {  
        cin>>n;  
        for(int i=1;i<=n;i++){  
          cin>>a[i];  
          a[i+n]=a[i]; 
        }  
        for(int j=2;j<=n+n;j++){  
          for(int i=j-1;i>=1&&j-i<n;i--){  
            int maxV=0;  
            for(int k=i;k<j;k++){  
              if(maxV<dp[i][k]+dp[k+1][j]+a[i]*a[k+1]*a[j+1])  
                maxV=dp[i][k]+dp[k+1][j]+a[i]*a[k+1]*a[j+1];  }  
            dp[i][j]=maxV;  
            if(e<dp[i][j])e=dp[i][j];  
          }  
        }  
        cout<<e;  
        return 0;  
    } 
    

    Pascal :

    var
    n,i,j,k:longint;
    max:int64;
    a:array[-10..maxint] of int64;
    f:array[1..1000,1..1000] of int64;
    begin
    
    
    readln(n);
    for i:=1 to n do
    begin
    read(a[i]);
    a[n+i]:=a[i];
    end;
    for i:=2*n-1 downto 1 do
    for j:=i+1 to 2*n do
    for k:=i to j-1 do
    if f[i,k]+f[k+1,j]+a[i]*a[k+1]*a[j+1]>f[i,j] then
    begin
    f[i,j]:=f[i,k]+f[k+1,j]+a[i]*a[k+1]*a[j+1] ;
    if f[i,j]>max then max:=f[i,j];
    end;
    writeln(max div 2);
    
    
    end.
    
    
    
    • 1

    信息

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