Algorithm: Hdu 4597 play Game (interval DP)

Source: Internet
Author: User

Meaning

Alice and Bob play a game that has two numbers of positive integers in length n, each time they two

You can only select one of the two ends to take away from one of the sequences. They all want to get as big as possible.

Numbers and they are smart enough to choose the best strategy each time. Alice first chooses, asks

What is the sum of the numbers that Alice eventually gets?

Ideas

This question should be regarded as the interval DP bar, you can look at the prototype of this problem:

Other rules are the same, but only a number sequence, but also can only take the left and right at each end of a number, ask how much Alice to take? (This can be done uva-10891)

Only one line of numeric sequences can use F (i, j) to indicate a sequence of numbers with a range [I,j] segment to start with, up to how many digits to take

And this problem only becomes two lines of numerical sequence, then can be on the basis of above, add two dimension

To F (i, J, K, L), which means that the first sequence is left with the interval [i,j], and the second sequence is left with the interval [k,l], how much can you take?

When faced with a state of F (I, J, K, L), you have four choices:

1. Select the leftmost number in the first row

2. Select the rightmost number in the first row

3. Select the leftmost number in the second row

4. Select the rightmost number in the second row

So, F (i, J, K, L) can be by:

F (I+1, J, K, L)

F (i, j-1, K, L)

F (i, J, K+1, L)

F (i, J, K, L-1)

These four states are transferred,

Assuming that the current state is Alice's Choice, the last state is the maximum value that Bob chooses.

In order to make Alice the final and the largest, then you have to choose the top four states of the smallest turn,

Set SUM (i, J, K, L) to represent the sums of a sequence [I,j] segment and the sum of the [k,l] segment of the second sequence.

Sum (i, J, K, L)-The last time Bob took the value is equal to Alice can get the value

F (i, J, K, L) = SUM (i, J, K, L)-

min{

F (I+1, J, K, L)

F (i, j-1, K, L)

F (i, J, K+1, L)

F (i, J, K, L-1)

}

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.