Number of ways to make given coin change


here is the code the for find number of ways to get given amount with given coins , can u mark error or mistakes plz??

Hey @Ashu1318 I’ll debug it for you. Till then be patient.

Hey @Ashu1318 in your code you forgot in for loop of I to make dp[i] equal to INT MAX. Moreover in your second for loop if statement you also forgot to add another condition. Look at this Minimum coin change problem and correct your mistake :grinning:

i m not asking for min number of coins but number of ways to make price , given link by you is for min number of coins i think,

The link I have mentioned has some other problem tag but the solution is if the problem you have mentioned only.

but i also have done something similar to this bottom upproch but its not working plz have a look on code i have shared above…

Before line 9 , make dp[i] =INT_MAX
Line number 10, if statement also check dp[i-a[j]]!=INT_MAX
In line 11, make Dp[i] =min(dp[i], dp[i-a[j]]+1)
and then see

no its not working or i dont think this will give us number of ways to make change of given amount

in line number 20 you are doing this
cin>>n,m;
first correct this
and this implementation will work you can see here

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

sir, lets see one case we have amount 4, and 3 coins of {1,2,3}, so there would be total 4 ways we can get change of that amount st {1,1,1,1},{1,1,2},{1,3},{2,2}, but our logic is wrong for that one i means for all cases

In that case ,before return statement check whether dp[price] is INT_MAX or not.
if it is then return 0
otherwise return dp[price]

And I guess there won’t be so tough side cases. So try to submit it , it might get accepted.