for (int i = 0; i < coins.size(); ++i) { if (coins[i] <= target) { // check validity of a sub-problem result = min(ans, CoinChange(target - coins[i], coins) + 1); } } return memo[target] = result;