Dynamic programming and Markov potential theory