DP coin change with exact number of coins [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



DP coin change with exact number of coins [closed]



I have 1 to n coins.How many ways i can get n by using 1 to n coins exact k of them??For example I have to make 3 with 1,2,3 coins using exactly 2 coins. There are four ways:
(3,0)
(1,2)
(2,1)
(0,3)
How can I solve this iteratively? I've solved it recursively.
Here is the code: https://paste.ubuntu.com/p/C5sgF8JK23/



Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.





I'm voting to close this question as off-topic because it is not a programming question. (And if it was, no, we won't write all the code for you. Give it a try. Post here if you're truly stuck and can't find answers after searching.)
– Mat
Aug 10 at 15:09





Well ok, you have 1 to n coins. How many coins are you willing to pay for someone doing your homework?
– user463035818
Aug 10 at 15:12





How are (3, 0) and (0, 3) solutions? 0 isn't a coin and you need to use exactly 2 coins
– NathanOliver
Aug 10 at 15:14



(3, 0)


(0, 3)


0





Sorry because I didn't make the question clear.
– shakil
Aug 10 at 15:21




1 Answer
1



Due to the fact, that this seems like an basic question, here a simple and easy complexity n^2 solution in pseudocode:


for i in all_available_coins
for j in all_available_coins
if j + i == sum
add to result list



Edit: Sry Overread the fact, that you mentioned 1 to n coins, but still the solution is scalable but highly uneffective because of n^k complexity

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard