1

I am studying recursive formulas in the famous coins problem in dynamic programming. However, I cannot solve this variation where there is a constraint where each coin (a power of two) could be used at most twice.

I know the recursive formula for the standard coin problem is as follows:

count[0]=1
def solve(x, coins):
    if (x<0): return 0
    else if x==0: return 1
    else:
        sum = 0 
        for c in coins:
            sum += solve(x-c)
        count[x]=sum
        return sum 

However, I am stuck at this constraint.

Stef
  • 13,242
  • 2
  • 17
  • 28
  • I’m not understanding your problem. Your title sounds to me like the binary representation of the number x. Is that what you’re asking for? – pjs Apr 08 '23 at 13:53
  • I am guessing the problem is "find the total number of possible solutions" and not just "find one solution"? – Stef Apr 12 '23 at 08:52
  • Your "recursive formula" is not a recursive formula, it's the pseudocode for a recursive function. However, it is obviously wrong: the recursive call `solve(x-c)` is not correct, since `solve` expects two arguments. – Stef Apr 12 '23 at 08:54

0 Answers0