#include<stdio.h>
#include<string.h>
int hash[2005][2005];
int treat[2005];
int num;
int dfs(int head,int tail,int n);
int main()
{
int i,k;
while(scanf("%d",&num)!=EOF)
{
memset(hash,0,sizeof(hash));
for(i=0;i<num;i++)
scanf("%d",&treat[i]);
k=dfs(0,num-1,1);
printf("%d\n",k);
}
return 0;
}
int dfs(int head,int tail,int n)
{
int max=0,k1,k2;
if(n>num) return 0;
if(hash[head][tail]) return hash[head][tail];
k1=n*treat[head]+dfs(head+1,tail,n+1);
k2=n*treat[tail]+dfs(head,tail-1,n+1);
max=k1>=k2?k1:k2;
hash[head][tail]=max;
return max;
}
DP我不会,我只会DFS+记忆化来剪枝。。。。。