Question

Consider there is a row of n coins and you and a friend are playing a...

Consider there is a row of n coins and you and a friend are playing a game (note: n is even). On your turn you can pick either the left most or the right most coin. Once you take a coin, a new coin is exposed. You have perfect information about what coins are available. Design an algorithm which gets you the maximum amount of money possible. Assume your friend is as clever as you are.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

TO FIND THE MAXIMUM AMOUNT OF MONEY POSSIBLE:

int maxLoot(int *hval, int n)

{

    if (n == 0)

        return 0;

    if (n == 1)

        return hval[0];

    if (n == 2)

        return max(hval[0], hval[1]);

// dp[i] represent the maximum amount of money

int dp[n];

// Initialize the dp[0] and dp[1]

    dp[0] = hval[0];

    dp[1] = max(hval[0], hval[1]);

// Fill remaining positions

    for (int i = 2; i<n; i++)

        dp[i] = max(hval[i]+dp[i-2], dp[i-1]);

return dp[n-1];

}

Add a comment
Know the answer?
Add Answer to:
Consider there is a row of n coins and you and a friend are playing a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • USING RECURSIONN!!! JAVA CODE Coin game: Alice and Bob are playing a game using a bunch...

    USING RECURSIONN!!! JAVA CODE Coin game: Alice and Bob are playing a game using a bunch of coins. The players pick several coins out of the bunch in turn. Each time a player is allowed to pick 1, 2 or 4 coins, and the player that gets the last coin is the winner. Assume that both players are very smart and he/she will try his/her best to work out a strategy to win the game. For example, if there are...

  • A friend of yours is given the following problem: You have 8 seemingly identical coins, among...

    A friend of yours is given the following problem: You have 8 seemingly identical coins, among which you are told that one is a counterfeit. The counterfeit is known to be heavier than a true coin. You have access to a simple two-pan balance. What is the MINIMUM number of weighings you need to use in order to find the counterfeit coin? Your friend's answer is the following: I can identify the counterfeit coin by proceeding as follows: Weighing 1:...

  • Design an O(n)-time non-losing strategy for the first player, Alice, in the coins in-a-line game. Your...

    Design an O(n)-time non-losing strategy for the first player, Alice, in the coins in-a-line game. Your strategy does not have to be optimal, but it should be guaranteed to end in a tie or better for Alice. Coins in a Line 12.4.1 The first game we consider is reported to arise in a problem that is sometimes asked during job interviews at major software and Internet companics (probably because it is so tempting to apply a greedy strategy to this...

  • 2. (10%) Suppose that among n identical-looking coins, one is fake. With a balance scale, we...

    2. (10%) Suppose that among n identical-looking coins, one is fake. With a balance scale, we can compare any two sets of coins. That is, by tipping to the left, to the right, or staying even, the balance scale will tell whether the two sets weight the same, or which of the two sets is heavier than the other but not by how much. Please use the prune and search strategy to design an efficient algorithm for detecting the fake...

  • 10. Dallin and Ari are playing a simple came. They each can choose Monkey or Wombat....

    10. Dallin and Ari are playing a simple came. They each can choose Monkey or Wombat. If they both pick Wombat, both receive 3. If they both choose Monkey, each receives 3. If Ari choose Monkey and Dallin choose Wombat, Ari gets 6 and Dallin gets 4. If Dallin choose Monkey and Ari chooses Wombat, Dallin gets 6 and Ari 4. The game is non-cooperative in all iterations. a. In a sequential game, illustrate the game and what happens when...

  • 10. Dallin and Ari are playing a simple came. They each can choose Monkey or Wombat....

    10. Dallin and Ari are playing a simple came. They each can choose Monkey or Wombat. If they both pick Wombat, both receive 3. If they both choose Monkey, each receives 3. If Ari choose Monkey and Dallin choose Wombat, Ari gets 6 and Dallin gets 4. If Dallin choose Monkey and Ari chooses Wombat, Dallin gets 6 and Ari 4. The game is non-cooperative in all iterations. In a sequential game, illustrate the game and what happens when Dallin...

  • 5. (3 points) Consider a hypothetical country Binary Land where they only use coins. There are...

    5. (3 points) Consider a hypothetical country Binary Land where they only use coins. There are n types of coins of denominations 1, 21, 22, 2,..., 2-1. Suppose you are a bank teller in Binary Land and your job is to give money to customers for any requested value V that is an integer. You should minimize the number of coins while paying V units of money. Design an algorithm that takes V as input and outputs the payment method...

  • In C++. Write a class named FBoard for playing a game, where player x is trying to get her piece to row 7 and player o i...

    In C++. Write a class named FBoard for playing a game, where player x is trying to get her piece to row 7 and player o is trying to make it so player x doesn't have any legal moves. It should have: An 8x8 array of char for tracking the positions of the pieces. A data member called gameState that holds one of the following values: X_WON, O_WON, or UNFINISHED - use an enum type for this, not string (the...

  • Using MATlLab You are playing the board game “Risk” when your friend asks you: “Do you...

    Using MATlLab You are playing the board game “Risk” when your friend asks you: “Do you think it is more likely to roll a total of eight or nine when rolling three dice?” Develop a program to determine if the probability of rolling an eight or a nine is greater To do this, you will need to check every possible combination of dice rolls (for example: 1-1-1, 1-2-3, 6-6-6) Hint: Nested for loops to count rolls of eight and nine...

  • Write a class named FBoard for playing a game... PLEASE USE C++ PLEASE DO NOT USE "THIS -->". NOT ALLOWED PLE...

    Write a class named FBoard for playing a game... PLEASE USE C++ PLEASE DO NOT USE "THIS -->". NOT ALLOWED PLEASE PROVIDE COMMENTS AND OUTPUT! Write a class named FBoard for playing a game, where player x is trying to get her piece to row 7 and player o is trying to make it so player x doesn't have any legal moves. It should have: An 8x8 array of char for tracking the positions of the pieces. A data member...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT