Consider a two player coin game where each player gets turn one by one. There is a row of even number of coins, and a player on his/her turn can pick a coin from any of the two corners of the row. The player that collects coins with more value wins the game. Develop a strategy for the player making the first turn, such he/she never looses the game.
Note that the strategy to pick maximum of two corners may not work. In the following example, first player looses the game when he/she uses strategy to pick maximum of two corners.
18 20 15 30 10 14 First Player picks 18, now row of coins is 20 15 30 10 14 Second player picks 20, now row of coins is 15 30 10 14 First Player picks 15, now row of coins is 30 10 14 Second player picks 30, now row of coins is 10 14 First Player picks 14, now row of coins is 10 Second player picks 10, game over. The total value collected by second player is more (20 + 30 + 10) compared to first player (18 + 15 + 14). So the second player wins.
Note that this problem is different from Optimal Strategy for a Game | DP-31. There the target is to get maximum value. Here the target is to not loose. We have a Greedy Strategy here. The idea is to count sum of values of all even coins and odd coins, compare the two values. The player that makes the first move can always make sure that the other player is never able to choose an even coin if sum of even coins is higher. Similarly, he/she can make sure that the other player is never able to choose an odd coin if sum of odd coins is higher.
18 20 15 30 10 14 Sum of odd coins = 18 + 15 + 10 = 43 Sum of even coins = 20 + 30 + 14 = 64. Since the sum of even coins is more, the first player decides to collect all even coins. He first picks 14, now the other player can only pick a coin (10 or 18). Whichever is picked the other player, the first player again gets an opportunity to pick an even coin and block all even coins.
15 7 2 2 30 2 10
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Game Theory (Normal-form game) | Set 3 (Game with Mixed Strategy)
- Game Theory (Normal-form Game) | Set 6 (Graphical Method [2 X N] Game)
- Game Theory (Normal-form Game) | Set 7 (Graphical Method [M X 2] Game)
- Predict the winner in Coin Game
- Find the player who will win the Coin game
- Optimal Strategy for a Game | Special Gold Coin
- Greedy approach vs Dynamic programming
- Maximum profit by buying and selling a share at most K times | Greedy Approach
- Travelling Salesman Problem | Greedy Approach
- Combinatorial Game Theory | Set 2 (Game of Nim)
- Game Theory (Normal - form game) | Set 1 (Introduction)
- Game Theory (Normal-form Game) | Set 4 (Dominance Property-Pure Strategy)
- Game Theory (Normal-form Game) | Set 5 (Dominance Property-Mixed Strategy)
- Coin Change | DP-7
- Minimum cost for acquiring all coins with k extra coins allowed with every coin
- Count ways to distribute exactly one coin to each worker
- Activity Selection Problem | Greedy Algo-1
- Huffman Coding | Greedy Algo-3
- Prim’s MST for Adjacency List Representation | Greedy Algo-6
- Dijkstra's shortest path algorithm | Greedy Algo-7
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.