← RoseCode

ROSECODE 436

Best Matrices Multiplication

Philippe_57721 · Programming ·

Let said the cost for the product of 2 matrices of size (p,q) and (q,r) is p×q×r.

Let's take 4 matrices with respective sizes:
A : (50, 20)
B : (20, 1)
C : ( 1, 10)
D : (10, 100)

We have 5 different ways to multiply these matrices with very different costs:
A×(B×(C×D))=103000
A×((B×C)×D)=120200
(A×B)×(C×D)=7000
(A×(B×C))×D=60200
((A×B)×C)×D=51500

The smallest cost is 7000

We take 50 matrices with respective sizes:
 (8737, 1458) (1458, 1629) (1629, 5104) (5104, 8634) (8634, 9493)
 (9493, 1380) (1380,  898) ( 898, 3036) (3036, 5012) (5012, 2405)
 (2405, 5697) (5697, 6520) (6520, 4777) (4777, 4031) (4031, 3752)
 (3752, 7848) (7848, 7540) (7540, 2624) (2624, 2436) (2436, 4598)
 (4598, 1020) (1020, 9050) (9050, 7031) (7031, 8692) (8692,   48)
 (  48,  396) ( 396, 2747) (2747, 4224) (4224, 9760) (9760, 8525)
 (8525,  391) ( 391,  714) ( 714, 4590) (4590, 1455) (1455, 5437)
 (5437, 4039) (4039, 6210) (6210, 7036) (7036, 5152) (5152, 4300)
 (4300, 3511) (3511, 2484) (2484,  449) ( 449, 5683) (5683, 9809)
 (9809, 4691) (4691, 3968) (3968, 3950) (3950, 5605) (5605, 1983)
 
What is the smallest cost for multiplying these matrices?

Answer format: cost

[My timing : < 1 sec]