POJ 3186
水题,思路很简单,不过这里有一个另一思路,也蛮有启发性的(关于状态定义)
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn = 2005;
int v[maxn];
int dp[maxn][maxn];
int main(int argc, char const *argv[])
{
int n;
scanf("%d", &n);
for (int i= 1; i<= n; ++i){
scanf("%d", v+i);
}
memset(dp, 0, sizeof(dp));
for (int k= 0; k< n; ++k){
int j= 1+k;
for (int i= 1; j<= n; ++i, ++j){
dp[i][j]= max(dp[i+1][j]+v[i]*(n-k), dp[i][j-1]+v[j]*(n-k));
}
}
cout<<dp[1][n]<<endl;
return 0;
}