Dynamic programming and quantum mechanical motion