poj 3186 Treats for the Cows dp

 

#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;
}

 

posted @ 2014-08-17 10:04  贝尔摩德  阅读(128)  评论(0编辑  收藏  举报