Practical strategy of algorithmic problem--chaper9--dynamic programming technique

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.