Dynamic Solution for Optimal Control Problem