我在试着找出需要多少硬币才能找出零钱,其中一个条件是先给出大硬币.例如10-5-2-1.我知道这个任务可以用循环来解决,但我想知道如何用递归来解决它
有一张桌子:
coin
| id | coin |
| ---- | ------ |
| 1 | 1 |
| 2 | 2 |
| 3 | 5 |
| 4 | 10 |
即更改=43
43 - 10 = 33 -> 33 - 10 = 23 -> 23 - 10 = 13 -> 13 - 10 = 3 -> 3 can't be decrease by 10
3 - can't be decrease by 5
3 - 2 = 1 -> 1 - can't be decrease by 2
1 - 1 = 0 -> end
One of example how i try solve this problem 个
试图获得:
输出:
| id | count | -- how many times coin was used/iterration count
| ---- | ------ |
| 4 | 4 |
| 3 | 0 |
| 2 | 1 |
| 1 | 1 |