Implemented solver using dynamic programming