dp solution for brackets in equation