Matrix Chain Multiplication Cost
Given an array `dims` of length `m`, matrix `i` (1-indexed in order) has dimensions `dims[i - 1] x dims[i]` for `1 <= i < m`. The matrices must be multiplied in this fixed order, but you may choose any parenthesization. Multiplying a `p x q` matrix by a `q x r` matrix costs `p * q * r` scalar multiplications and produces a `p x r` matrix.