In: Computer Science
Two players play a game where they start with a row of n piles of varied amounts of money. The players take turns and in each turn a player can pocket either the money in the first pile or the last pile in the row of piles that remains. Design an efficient algorithm (using dynamic programming), which on any given sequence of amounts, determines the maximum amount of money that player 1 can win.
If n is even, prove that player 1 wins at least half the money available. If n is odd, player 1 actually gets one more pile than player 2. In spite of that, show with a simple example that player 1 can be left with far less than half the total amount.
Note: you can write the algorithm either in plain English or in pseudocode.