This problem can't be solved by greedy method.
for example, a matrix chain [3x2]•[2x3] •[3x4].
The consequence will be (([3x2]•[2x3]) •[3x4]) using greedy method, but the optimal answer is ([3x2]•([2x3] •[3x4])).
More details:https://www.cs.washington.edu/education/courses/421/04su/slides/matrixchain.pdf