标签:
先模拟一下确定理解题意,然后再找状态转移方程,注意方向~
1 //sicily 1345 能量项链 2 #include <bits/stdc++.h> 3 4 using namespace std; 5 6 int a[205]; 7 int dp[205][205]; 8 9 int main() 10 { 11 int n; 12 while(cin >> n) 13 { 14 memset(dp, 0, sizeof(dp)); 15 for(int i=0; i<n; i++) 16 { 17 cin >> a[i]; 18 a[i+n] = a[i]; 19 } 20 for (int i=2*n-1; i>=0; i--) 21 { 22 for (int j=i+2; j<2*n; j++) 23 { 24 for (int k=i+1; k < j; k++) 25 dp[i][j] = max(dp[i][j], dp[i][k]+dp[k][j]+a[i]*a[j]*a[k]); 26 } 27 } 28 int maxx=0; 29 for (int i=0; i<n; i++) 30 { 31 maxx = max(maxx, dp[i][i+n]); 32 } 33 34 printf("%d\n", maxx); 35 } 36 return 0; 37 }
标签:
原文地址:http://www.cnblogs.com/dominjune/p/4575587.html