matrix chain algorithm. print optimal brackets