As suggested in both Quora and StackOverflow, the `coin change`

problem should be the second problems for beginner to solve.

There are actually multiple variations of this problem, however, my approach will be finishing the basic version first, which is:

**Given a set of coins with values, find the possible way to form N (order is not considered).**

**Example**: Given coins {2, 3, 5, 6}, find the possible way to form 10.

**Approach:** Top-down approach

**Logic flow:** Repeatedly minus coin value from N recursively until it reaches zero / negative value.

This is the parameters list of my method

`int cal(int N, vector<int> coins, vector<int>mem)`

- If N equal 0, return 1 (Which mean the coins set can successfully form N)
- check if
`mem[N]`

exists - If yes, return
`mem[N]`

- If no, set
`int rest = 0`

- For each
`c`

in`coins`

: `res += cal(N - c, coins, mem)`

**Observation:**

##### For f(2) and coin set {2, 5, 3, 6}

1 2 3 4 5 |
= f(2-2) + f(2-5) + f(2-3) + f(2-6) = f(0) and return 1 + invalid + invalid + invalid f(2) = 1 and save to table mem[2] = 1 |

##### For f(4) and coin set {2, 5, 3, 6}

1 2 3 4 5 6 7 8 9 |
= f(4-2) + f(4-5) + f(4-4) + f(4-6) = f(2) + invalid + 1 + invalid = mem[2] + 1 = 2 f(4) = 2 and save to table mem[4] = 2 |

##### For f(6) and coin set {2, 5, 3, 6}

1 2 3 4 5 |
= f(6-2) + f(6-3) + f(6-5) + f(6-6) = f(4) + f(3) + f(1) + f(0) = mem[4] + f(3) + invalid + 1 |