Dynamic programming and its application in economics and finance