1、问题:
2、解析:
举个例子:
3、设计(核心伪代码):
for (int i = 1; i <= mm; i++){
for (int j = 0; j <= money; j++){
F[i][j] = 0;
m[i][j] = 0;
for (int k = 0; k <= j; k++){
if (F[i][j] < f[i][k] + F[i - 1][j - k]){
F[i][j] = f[i][k] + F[i - 1][j - k];
m[i][j]=k;
}
}
}
}
4、分析:
时间复杂度O(n) = Ω ( 2 n − 1 ) Ω(2^{n-1}) Ω(2n−1)