# 【kuangbin带你飞-区间DP-3】E - Multiplication Puzzle POJ-1651

## Input

The first line of the input contains the number of cards N (3 <= N <= 100). The second line contains N integers in the range from 1 to 100, separated by spaces.

## Output

Output must contain a single integer - the minimal score.

6
10 1 50 50 20 5

3650

## 状态转移方程

dp[l][r] = min {dp[l][k]+dp[k][r]+a[k]*a[l]*a[r]},l<k<r

### 代码

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 200;
const int inf = 0x3f3f3f3f;
int dp[maxn][maxn];
int a[maxn];
int main() {
ios::sync_with_stdio(false);//优化
int n;
cin >> n;
for(int i = 0; i < n; i++)
cin >> a[i];
memset(dp, inf, sizeof(dp));
for(int i = 0; i < n; i++) {
dp[i][i] = 0;
if(i < n - 1)
dp[i][i + 1] = 0;
}
for(int len = 3; len <= n; len++) {
for(int l = 0; l + len <= n; l++) {
int r = l + len - 1;
for(int k = l + 1; k < r; k++) {
dp[l][r] = min(dp[l][r], dp[l][k] + dp[k][r] + a[k] * a[l] * a[r]);
}
}
}
cout << dp[0][n - 1] << endl;
}



05-20 42

02-16 82

08-28 35

08-06 41

08-06 29

03-30 13

08-05 34

08-05 39

09-13 22

08-07 131

02-18 30

03-19 83万+

04-14 62万+

03-13 16万+

03-01 14万+

03-07 1万+

03-08 5万+

03-08 8万+

03-10 14万+

03-10 20万+

#### MySQL数据库面试题（2020最新版）

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客