improve io, next step need to use DP to memorize the calculation results.