Calc optimal matrix chain order