E

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstring>
 4 #include <cstdio>
 5 #include <string>
 6 #include <map>
 7 #include <cmath>
 8 #include <vector>
 9 
10 #define Faster ios::sync_with_stdio(false),cin.tie(0)
11 #define Read freopen("in.txt","r",stdin),freopen("out.txt","w",stdout)
12 #define Close fclose(stdin),fclose(stdout)
13 const int maxn = 105;
14 using namespace std;
15 const int MOD = 1e9+7;
16 typedef long long ll;
17 
18 #define INF 100000000
19 
20 int a[maxn];
21 int dp[maxn][maxn];
22 
23 int main(){
24     Faster;
25     int n;
26     cin >> n;
27     for(int i = 1;i <= n;i++){
28         cin >> a[i];
29     }    
30     memset(dp, 0, sizeof(dp));
31     for(int l = 2;l < n;l++){    //长度从2开始
32         for(int i = 2;i+l <= n+1;i++){
33             int j = i+l-1;
34             dp[i][j] = INF;
35             for(int k = i;k < j;k++){    //枚举中点
36                 dp[i][j] = min(dp[i][j], dp[i][k]+dp[k+1][j] + a[i-1]*a[k]*a[j]);
37             }
38         }
39     }
40     cout << dp[2][n] << endl;
41     return 0;
42 }
原文地址:https://www.cnblogs.com/ouyang_wsgwz/p/9177323.html