-1
long long num(long long p)
{
   if(p<0)
      return 0;
   if(p==0)
      return 1;
   if(t[p]!=0)
      return t[p];
   t[p]=num(p-1)+num(p-2)+num(p-5)+num(p-10)+num(p-20)+num(p-50)+num(p-100);
   return t[p];
}

I use this method num to count number of possible ways of coin change problem.The problem is this approach counts 1,1,2 and 1,2,1 as different which should be taken as 1 .How to do that? Cant find any good solution anywhere.

Aditi Rawat
  • 784
  • 1
  • 12
  • 15

1 Answers1

0

This is a C++ implementation of the number of distinct coin combos.

int combo(int d[], int r, int R)
{
    if (R == 0)
        return 1;
    if (R < 0)
        return 0;

    int tot = 0;

    for (int i = 0; i < r; i++) 
        tot += combo(d, r, R - d[i]);

    return tot;
}

Hope this helps.

Jake Freeman
  • 1,700
  • 1
  • 8
  • 15
  • But this is exactly same as my code except you used a for loop .This will count 1,1,2 and 1,2,1 as two different possibilities what i want is them to be counted as 1. – Aditya Upadhyay Dec 23 '17 at 06:03