matrix chain multiplication optimcal cost added as dynamic solution