A Tree-Structure Algorithm for Optimal Control Problems via Dynamic Programming