matrix chain and rod cutting problems