Dynamic Programming and Bayesian Inference