P2858 [USACO06FEB]Treats for the Cows G/S (区间DP)
思路:
AC代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e3+5;
int v[N],dp[N][N];
int main(){
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&v[i]);
for(int i=1,len=1;i<=n;i++,len++)
for(int l=1,r=l+len-1;r<=n;l++,r++)
dp[l][r]=max(dp[l+1][r]+v[l]*(n-i+1),dp[l][r-1]+v[r]*(n-i+1));
printf("%d\n",dp[1][n]);
return 0;
}