-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboj_11049.cpp
More file actions
38 lines (32 loc) · 827 Bytes
/
boj_11049.cpp
File metadata and controls
38 lines (32 loc) · 827 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
//<11049>번 : <행렬 곱셈 순서>
#include <bits/stdc++.h>
#define R first
#define C second
#define INF INT_MAX
using namespace std;
pair<long long, long long> a[500][500];
long long d[500][500];
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
int n, r, c;
cin >> n;
fill(d[0], d[500], INF);
for(int i = 0; i < n; i++) {
cin >> r >> c;
a[i][i] = {r,c};
d[i][i] = 0;
}
for(int range = 2; range <= n; range++) {
for(int i = 0; i <= n-range; i++) {
int j = i + range - 1;
a[i][j] = {a[i][i].R, a[j][j].C};
for(int k = i; k < j; k++) {
d[i][j] = min(d[i][j], a[i][k].R * a[i][k].C * a[k+1][j].C + d[i][k] + d[k+1][j]);
}
}
}
cout << d[0][n-1] << '\n';
return 0;
}