1

There is an array of 𝑛 coins with values 𝐶 = [𝑐1, 𝑐2, … , 𝑐𝑛]. The prices are positive integers and repetitions are allowed. For example, one possible sequence of coins is as follows: 𝐶7 = [5, 20, 2, 20, 1, 10, 50]. Your goal is to collect the maximum amount of money with the limitation that you will not get two coins lying next to each other in the original row. For example, if get coin 10 from 𝐶7, then you cannot get coins 1 or 50.

Can you find me the recursion equation for this problem?

I tried this but I'm not sure:

M(i) = max{ M(i−1), if we take the coin i
            M(i−2)+C[i], if we don't take the coin i
1
  • What are you not sure about in the algorithm you give? Why did you tag this with "recursion" and "dynamic-programming"? This looks like you're just asking someone here to do your homework for you. Commented Feb 22, 2024 at 8:27

1 Answer 1

0

Your solution looks right to me, except your labels are reversed. + C[i] corresponds to taking coin i, not the other way around.

I'd also add a base case if you haven't already.

Note that this is the house robber problem, so there are a ton of solutions online you can compare against.

See also: How do I solve the Coin Row problem using dynamic programming?.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.