https://www.luogu.org/problemnew/show/P2858
方程很好想,关键我多枚举了一次(不过也没多大关系)
#include <bits/stdc++.h>
#define read read()
#define up(i,l,r) for(register int i = (l);i <= (r); i++)
using namespace std;
const int N = ;
int n,a[N],f[N][N];
int read
{
int x = ;char ch = getchar();
while(ch < || ch > ) ch = getchar();
while(ch >= && ch <= ) {x = * x + ch - ; ch = getchar();}
return x;
}
//int mymax(int a,int b,int c){int x = max(a,b);int y = max(b,c); return max(x,y);}
int main()
{
n = read; up(i,,n) a[i] = read;
up(i,,n) f[i][i] = a[i];
up(L,,n)//枚举区间长度;
up(i,, (n-L+) ) //枚举左端点;
{
int j = i + L - ; int T = n + - L;
f[i][j] = max(f[i + ][j] + a[i] * T,f[i][j - ] + a[j] * T);//mymax(f[i][j],f[i + 1][j] + a[i] * T,f[i][j - 1] + a[j] * T);
}
printf("%d",f[][n]);
return ;
}