Gamified challenge · Interval DP
The chain has n = dims.length - 1 matrices M1 … Mn, where Mi has dims[i-1] rows and dims[i] columns, so neighbours always fit. Multiplying an a × b matrix by a b × c matrix costs a · b · c scalar multiplications and gives an a × c matrix.
The product is the same however you bracket it, but the work is not. Write minMults(dims) (Python min_mults) that returns the least total work for the whole chain. dims has at least 2 numbers; a single matrix costs 0.
Example: for [10, 30, 5, 60], (M1 M2) M3 costs 10·30·5 + 10·5·60 = 4500, while M1 (M2 M3) costs 30·5·60 + 10·30·60 = 27000. The answer is 4500.
This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.
Sign in with Google