Note: Standard combination generation:
1. Do not return when find diff < 0. Because i + 1 could satisfy.
2. Since it does not return, it requires check whether it reaches end of needs.
class Solution { public int shoppingOffers(Listprice, List
> special, List needs) { return generateComb(price, special, needs, new HashMap<>()); } private int generateComb(List price, List
> special, List needs, Map
, Integer> map) { if (map.containsKey(needs)) return map.get(needs); int currentValue = getValue(price, needs); for (List s : special) { List clone = new ArrayList<>(needs); int i = 0; for (; i < clone.size(); i++) { int diff = clone.get(i) - s.get(i); if (diff < 0) break; clone.set(i, diff); } if (i == needs.size()) currentValue = Math.min(currentValue, s.get(s.size() - 1) + generateComb(price, special, clone, map)); } map.put(needs, currentValue); return currentValue; } private int getValue(List price, List needs) { int result = 0; for (int i = 0; i < price.size(); i++) { result += price.get(i) * needs.get(i); } return result; }}