intMemorizedCutRodAux(constint *rodLen2Price, int curRodLen, int *optimalRodTotalMoney){ cout << "调用MemorizedCutRodAux"<< endl; if (optimalRodTotalMoney[curRodLen] >= 0) { return optimalRodTotalMoney[curRodLen]; }
int q = -1; if (curRodLen == 0) { q = 0; } else { for (int i = 1; i <=curRodLen ; ++i) { int tmp = rodLen2Price[i] + MemorizedCutRodAux(rodLen2Price, curRodLen-i, optimalRodTotalMoney); q = (q < tmp ? tmp : q); } }
optimalRodTotalMoney[curRodLen] = q; return q; }
intMemorizedCutRod(constint *rodLen2Price, int curRodLen){ int * optimalRodTotalMoney = newint[curRodLen + 1]; for (int i = 0; i <= curRodLen; ++i) { optimalRodTotalMoney[i] = -1; }