update dynamic programing algorithm