-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsm.py
More file actions
33 lines (26 loc) · 640 Bytes
/
Copy pathsm.py
File metadata and controls
33 lines (26 loc) · 640 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
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2019 miffyrcee <miffyrcee@localhost.localdomain>
#
# Distributed under terms of the MIT license.
"""
"""
import numpy as np
p = [5, 10, 3, 12, 5, 50, 6]
def mo(p):
n = len(p) - 1
m = np.ones((n, n)) * float('inf')
for i in range(n):
j = i
m[i][j] = 0
for l in range(1, n):
for i in range(l):
j = l - i
for k in range(i, j + 1):
m[i][j] = min(m[i][j],
m[i][k] + m[k + 1][j] + p[i] * p[k] * p[j])
return m
print('asdsf' [1:2])
print(mo(p))