标签:tput hint receives ase box nat period turn ati
Input
Output
Sample Input
5 1 3 1 5 2
Sample Output
43
Hint
#include <stdio.h> #include <string.h> #include <algorithm> using namespace std; #define MAXN 2002 /* 区间DP,从后向前推,dp[i][j]表示首端元素为a[i],尾端为a[j]的情况 dp[i][j] = max(dp[i+1][j]+t*a[i],dp[i][j-1]+t*a[j]) */ int a[MAXN],dp[MAXN][MAXN]; int main() { int n; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<=n;i++) dp[i][i] = n*a[i];//最后一个卖出元素是a[i]的情况 for(int l=1;l<n;l++) { for(int i=1;i+l<=n;i++) { int j = i+l; dp[i][j] = max(dp[i+1][j]+(n-l)*a[i],dp[i][j-1]+(n-l)*a[j]); } } printf("%d\n",dp[1][n]); return 0; }
标签:tput hint receives ase box nat period turn ati
原文地址:http://www.cnblogs.com/joeylee97/p/6652616.html