题解 | #跳跳跳#
跳跳跳
https://ac.nowcoder.com/acm/problem/227595
#include<iostream>
using namespace std;
int n;
int a[4010];
int dp[4010][4010];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=n+1;i<=2*n;i++) a[i]=a[i-n];
for(int len=1;len<=n;len++)
{
for(int i=1;i<=2*n-len+1;i++)
{
int j=i+len-1;
dp[i][j]=max(dp[i+1][j]+a[i]*len,dp[i][j-1]+len*a[j]);
}
}
int maxn=-1;
for(int i=1;i<=2*n;i++)
maxn=max(maxn,dp[i][i+n-1]);
cout<<maxn;
}