标签:ted man number blank orm body file money i++
题目链接:http://poj.org/problem?id=3186
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 6548 | Accepted: 3446 |
Description
Input
Output
Sample Input
5 1 3 1 5 2
Sample Output
43
Hint
Source
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <vector> 7 #include <queue> 8 #include <stack> 9 #include <map> 10 #include <string> 11 #include <set> 12 #define ms(a,b) memset((a),(b),sizeof((a))) 13 using namespace std; 14 typedef long long LL; 15 const double EPS = 1e-8; 16 const int INF = 2e9; 17 const LL LNF = 2e18; 18 const int MAXN = 2e3+10; 19 20 int n; 21 int a[MAXN], dp[MAXN][MAXN]; 22 23 int main() 24 { 25 while(scanf("%d", &n)!=EOF) 26 { 27 for(int i = 1; i<=n; i++) 28 scanf("%d", &a[i]); 29 30 for(int i = 1; i<=n; i++) 31 dp[i][i] = a[i]*n; 32 33 for(int len = 2; len<=n; len++) 34 for(int i = 1; i+len-1<=n; i++) 35 { 36 int j = i+len-1; 37 dp[i][j] = max(dp[i+1][j]+(n-len+1)*a[i], dp[i][j-1]+(n-len+1)*a[j]); 38 } 39 40 printf("%d\n", dp[1][n]); 41 } 42 }
POJ3186 Treats for the Cows —— 区间DP
标签:ted man number blank orm body file money i++
原文地址:http://www.cnblogs.com/DOLFAMINGO/p/7631257.html