#include <cstdio> #include <algorithm> using namespace std; #define maxn 2100 int dp[maxn][maxn]; int val[maxn]; int n; int main() { while(scanf("%d",&n)!=EOF) { int i,j; for(i=1;i<=n;i++) { scanf("%d",&val[i]); dp[i][i]=n*val[i]; } for(i=n-1;i>=1;i--) for(j=i;j<=n;j++) { int fac=n-(j-i); dp[i][j]=max(dp[i+1][j]+fac*val[i],dp[i][j-1]+fac*val[j]); } printf("%d\n",dp[1][n]); } return 0; }
poj 3186 Treats for the Cows dp
时间: 2024-10-20 03:51:02