Q1:
Number games:
Two persons (A, B) a row of board games lined with n integers, the game starts with a, each person has the following actions:
(1) Take the right or left-hand piece of the board and erase the removed number from the board.
(2) When there are more than two numbers left in the chessboard, you can erase the two numbers on the right or left of the chessboard.
When all the numbers on the board disappear, the game ends, who takes the pieces representing the sum of the larger number of people who win, now assume that two players are smart and give a sequence of length n, calculate the difference between A's score and B's score after the game ends.
Analysis: In fact, similar problems in the "training Guide" has been analyzed, the topic is called "Sum game", this type of question is based on dynamic rules of the game, and board games to use the most minimal minimax algorithm is essentially the same.
So back to this question, we see that it is based on a one-dimensional integer sequence, so whether it is a game or something, we can use the linear DP approach to its sub-problem.
Set Dp[left][right] Indicates the score of the player facing the interval [left,right] and the margin of the remaining player's score, then we will get the following state transition equation (with board[] to store n integers):
The final answer is Dp[1][n].
Practical strategy of algorithmic problem--chaper9--dynamic programming technique