DP: Coin Change

  • + 0 comments

    Anyone know what change is needed to only return the number of odd solutions? Eg given the coins [1,2,5] and amount 5. The solutions are: [1,1,1,1,1] [2,111] [2,2,1] [5] There are four solutions, but only three odd solutions. I'm tearing my hair out trying to solve this.

    def make_change(coins, n): lookup = [1] + [0] * n coins_used_list = [] coins_used_counter = 0 for coin in coins: for amount in range(n+1-coin): lookup[amount+coin] += lookup[amount] return lookup[n]

    make_change(coins = [1,2,5], n = 5)