 # Coin Change Problem

I tried solving a different question of this same type where we are told to calculate the total nmber of ways to form a total using a coins array…what is going wrong in my code plz correct it

at line no 24
correct statement will be
int subproblem = solve(arr, n - arr[i], m)+1;
you also have to add 1

for which input you are trying?

N=4
arr={1,2,3}
this is my input

POssible ways can be 1111 22 13 112

This question is just a variation of the question shown in videos right so the logic is correct no?

actually the problem is
first you set dp=1 and then you use menset to set all values=0

so dp=1 should be used later

I made some changes…but no luck…

this will not work
previous one is better
but there is also problem with that
it is considering the reduntant case also
for example for n=4
it is considering
1 1 1 1
1 1 2
1 2 1
1 3
2 1 1
2 2
3 1

as you can see there is repetation
so this approach is not correct

this is correct way to do this
using memoization
you have to make 2D array

I am a bit confused about how to decide m and n as column or row if i would have taken n as columns and m as rows would the answer differ?

Can u please explain ur intuition for choosing rows and columns

no there will be no problem
why should ans differ?
you are storing the ans of m,n at dp[m][n] and using it when required
if you use dp[n][m] then also you can use it

okay understood Thank you