Row seat &&little Elephant and permutation--arrangement DP processing

Source: Internet
Author: User

The problem of permutation is to order the sequence so that it reaches an optimal value or a number of statistical schemes.

DP can solve partial permutation problems.

The usual solution is to sort decisions by number (priority), left-to-right, and both.

This is mainly the first one.

Row seats
? Yes?? The individual sits in a row
? For two adjacent people??,??
? If?? <??, it will produce???? + ???? The Pleasure degree
? Otherwise it will produce???? + ???? The Pleasure degree
? Ask for a permutation to maximize pleasure
? ?? ≤3000

From left to right, the decision must be pressed.

But it can be found that we do not care about who I am, only the relative size of the number and I.

Moreover, this contribution AI,BJ,CI,DJ can be independent.

The idea is more natural.

We follow the numbers from small to large decisions.

There are several places for each point I:

1. The left and right are smaller than I.

2/3. Left/Right ratio i large.

4. It is bigger than I.

But the trouble is, if the direct DP may not eventually form a sequence.

Not a whole paragraph.

Therefore, the concept of paragraph should also be introduced.

The decision of I is:

1. The left and right are smaller than I, that is, two paragraphs before the connection.

2/3. The left/right ratio i is large, the other is smaller than I, that is, connecting a segment.

4. The left and right are larger than I, that is I from a paragraph.

Each of these, I contribute to the answer can be on-site statistics.

Because, our numbers are processed from small to large,

If we can connect correctly, this contribution must be counted.

F[I][J] said, the processing of the first number I, the formation of a J section of the program number.

Another problem is that the border situation, no left/right, does not have this contribution.

Then you can F[I][J][0/1][0/1] to indicate whether to put the leftmost rightmost.

Answer: F[n][1][1][1]

Solution:

The AI is assumed to be a 1~n sequence.

For a legitimate bi sequence, multiplying the n! is the case for all AI and bi.

In this way, the contribution is more good statistics.

Dp[i][j][k] indicates that the first I position in BI is processed, there are J is empty, contribution is the number of schemes of K.

Look at this:

In fact, there is a question: (Although not DP)

Fun Home Garden

Row seat &&little Elephant and permutation--arrangement DP processing

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.