码迷,mamicode.com
首页 > 其他好文 > 详细

P1063 能量项链

时间:2020-02-01 16:17:40      阅读:72      评论:0      收藏:0      [点我收藏+]

标签:info   blank   names   const   https   class   include   http   c++   

题目链接

技术图片

 

 

Code:

 1 #include <bits/stdc++.h>
 2 # define LL long long
 3 using namespace std;
 4 
 5 const int maxn=100+10;
 6 int N;
 7 int val[maxn];
 8 int dp[maxn][maxn];
 9 
10 int pre(int i){
11     return i==1?N:i-1;
12 }
13 
14 int next(int i){
15     return i==N?1:i+1;
16 }
17 
18 int dfs(int left, int right){
19     if(dp[left][right]!=-1) return dp[left][right];
20 
21     int res=0;
22     for(int i=left;i!=right;i=next(i)){
23         int tmp=val[left]*val[next(i)]*val[next(right)]+dfs(left,i)+dfs(next(i),right);
24         res=max(res,tmp);
25     }
26     return dp[left][right]=res;
27 }
28 
29 int main(){
30     memset(dp,-1,sizeof(dp));
31     scanf("%d", &N);
32     for(int i=1;i<=N;++i){
33         scanf("%d", val+i);
34     }
35     int res=0;
36     for(int i=1;i<=N;++i){
37         res=max(res,dfs(i,pre(i)));
38     }
39     printf("%d", res);
40 }

 

P1063 能量项链

标签:info   blank   names   const   https   class   include   http   c++   

原文地址:https://www.cnblogs.com/FEIIEF/p/12248576.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!