和noip2005矩阵取数游戏是几乎相同的题,在洛谷上只有黄题,但是我觉得如果对于只做过基础的区间dp的同学来说,能自己推出这题的状态,那是很厉害的了,状态有点不一样,
#include <bits/stdc++.h>
using namespace std;
const int N=2e3+5;
int n;
int a[N],f[N][N];
int main(){
scanf("%d",&n);
for (register int i=1; i<=n; ++i) scanf("%d",&a[i]);
for (register int i=1; i<=n; ++i) f[i][i]=a[i]*n;
for (register int l=2; l<=n; ++l)
for (register int i=1; i+l-1<=n; ++i)
{
int j=i+l-1;
f[i][j]=max(f[i+1][j]+a[i]*(n-(j-i)),f[i][j-1]+a[j]*(n-(j-i)));
}
printf("%d\n",f[1][n]);
return 0;
}
来源:CSDN
作者:Dove_xyh
链接:https://blog.csdn.net/Dove_xyh/article/details/103772920