int search(const vector& coins, int amount){
if(amount == 0)
return 0;
if(dp[amount] != -1)
return dp[amount];
int res = max_amount;
for(int coin: coins)
if(amount - coin >= 0)
res = min(res, 1 + search(coins, amount -coin));
return dp[amount] = res;
}
老师:按照0-1 完全背包,递推关系应该为:dp[i] = min(dp[i], dp[i - coins[j]] + 1)
而这个记忆化搜索的递推关系怎么理解? 这里的for 循环是 依次考虑从第0 个 coin 到第最后一个coin 是否放在背包里的分情况处理么?