-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11049.cpp
More file actions
47 lines (41 loc) · 894 Bytes
/
11049.cpp
File metadata and controls
47 lines (41 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#define INF 987654321
using namespace std;
vector<pair<int, int>> matrixs;
vector<vector<int>> dp;
int multiple(int left, int right)
{
if (dp[left][right] != -1)
{
return dp[left][right];
}
int re = INF;
if (left == right)
{
re = 0;
}
else
{
for (int i = left; i < right; i++)
{
re = min(re, multiple(left, i) + multiple(i + 1, right) + matrixs[left].first * matrixs[i].second * matrixs[right].second);
}
}
return dp[left][right] = re;
}
int main()
{
int N;
scanf("%d", &N);
matrixs.assign(N, {0, 0});
dp.assign(N, vector<int>(N, -1));
for (int i = 0; i < N; i++)
{
scanf("%d %d", &matrixs[i].first, &matrixs[i].second);
}
printf("%d\n", multiple(0, N - 1));
return 0;
}