dynamaic programming optimization CMEX routine