I am given an amount say . I am given some denominations say
I am given an amount say $50. I am given some denominations say $1 ,$2 ,$5 etc. and the number of these denominations eg 1 ,5,6 that means 1 coin/note of $1 ,5 coins/notes of $2 and 6 coins/notes of $5. I have to find the number of ways these coins can be used to form this amount $50. I am trying to think an efficient algorithm to solve this in the fastest time possible. Please note here the amount will never exceed $60.
我得到了50美元的金额。给我一些面额说1美元,2美元,5美元等等,这些面额的数量,例如1,5,6,这意味着1美元/ 1美元的钞票,5美元/ 2美元的钞票和6美元的钞票/ 5美元的钞票。我必须找到这些钱币可以用来形成50美元的方式。我试图在最快的时间内考虑一种有效的算法来解决这个问题。请注意,这笔金额不会超过60美元。
Can someone please suggest which algorithm I can use to solve this problem? Till now I have written a recursive solution for this problem but it is too slow for my purpose.I will be posting it here soon.
有人可以建议我可以使用哪种算法来解决这个问题吗?直到现在我已经为这个问题写了一个递归解决方案,但它对我来说太慢了。我将很快在这里发布。
1 个解决方案
#1
0
I agree that this is not the place for homework, but still... The asker does not expect to get solution, he is only asking for a direction. let's not keep questions open unecessarily
我同意这不是家庭作业的地方,但仍然......提问者不期望得到解决方案,他只是在寻求方向。让我们不要让问题保持不变
Have a look at Integer factorization
看看整数分解
, , etc. and the number of these denominations eg 1 ,5,6 that means 1 coin/note of
I am given an amount say $50. I am given some denominations say $1 ,$2 ,$5 etc. and the number of these denominations eg 1 ,5,6 that means 1 coin/note of $1 ,5 coins/notes of $2 and 6 coins/notes of $5. I have to find the number of ways these coins can be used to form this amount $50. I am trying to think an efficient algorithm to solve this in the fastest time possible. Please note here the amount will never exceed $60.
我得到了50美元的金额。给我一些面额说1美元,2美元,5美元等等,这些面额的数量,例如1,5,6,这意味着1美元/ 1美元的钞票,5美元/ 2美元的钞票和6美元的钞票/ 5美元的钞票。我必须找到这些钱币可以用来形成50美元的方式。我试图在最快的时间内考虑一种有效的算法来解决这个问题。请注意,这笔金额不会超过60美元。
Can someone please suggest which algorithm I can use to solve this problem? Till now I have written a recursive solution for this problem but it is too slow for my purpose.I will be posting it here soon.
有人可以建议我可以使用哪种算法来解决这个问题吗?直到现在我已经为这个问题写了一个递归解决方案,但它对我来说太慢了。我将很快在这里发布。
1 个解决方案
#1
0
I agree that this is not the place for homework, but still... The asker does not expect to get solution, he is only asking for a direction. let's not keep questions open unecessarily
我同意这不是家庭作业的地方,但仍然......提问者不期望得到解决方案,他只是在寻求方向。让我们不要让问题保持不变
Have a look at Integer factorization
看看整数分解
,5 coins/notes of and 6 coins/notes of . I have to find the number of ways these coins can be used to form this amount . I am trying to think an efficient algorithm to solve this in the fastest time possible. Please note here the amount will never exceed .I am given an amount say . I am given some d