Quadrilateral inequality Optimization

Source: Internet
Author: User

Information about quadrilateral inequality or stone combination. There are many websites. However, many of them are not detailed, so it is hard to understand them by throwing a few conclusions directly. This articleArticleThe combination of stones is used as an example. Prove some conclusions about quadrilateral inequality. It is a review.

[Question surface]

A row of n (n ≤ 20) stones are placed on a playground. Now we need to combine the stones into a pile in order. It is specified that only two adjacent stones can be selected at a time to merge into a new pile, and the number of new stones is recorded as the score of the merge.

Try programming to find the minimum score and maximum score of combining N piles of stones into a pile and the corresponding merge plan.

【AlgorithmAnalysis]

We will only discuss the minimum score, which is similar to the maximum score.

Set

F [I, j] = min {f [I, K] + F [k + 1, J] + W [I, j]} {I <= k <j}, in particular, F [I, I] = 0.

Obviously, this is an O (N ^ 3) Dynamic gauge.

[Algorithm optimization]

The following is a major event.

First, two definitions are given:

(1) When the function W [I, j] satisfies W [I, j] + W [I ', J'] <= W [I ', when J] + W [I, j '], I <= I' <= j ', W satisfies the Quadrilateral inequality.

(2) When the function W [I, j] satisfies W [I ', J] ≤ W [I, j'], I <= I '<= j' is called W.

Obviously, the W [I, j] defined at the beginning satisfies the Range inclusion relationship and quadrilateral inequality.

Now we want to prove that f [I, j] = min {f [I, K] + F [k + 1, J] + W [I, j]} {I <= k <j} also satisfies the Quadrilateral inequality.

We use mathematical induction to generalize the Interval Length in the Quadrilateral inequality.

The proof is as follows:

When I = I 'or J = J', the inequality is obviously true. Therefore, when l ≤ 1, function f satisfies the Quadrilateral inequality.

The following two cases are summarized and proved:

Scenario 1: I <I '= j <j'

In this case, the Quadrilateral inequality is simplified to the following inequality: F [I, j] + F [J, j '] ≤ f [I, j'] + 0, set K = max {p | f [I, J'] = f [I, P-1] + F [p, J'] + W [I, J']}, in two cases, K ≤ j or k> J. The following is a similar case where K is less than or equal to J and K> J.

Case 1.1: K ≤ j. At this time:

Case 1.2: k> J, omitted

Scenario 2: I <I '<j'

Set y = max {p | f [I ', J] = f [I', P-1] + F [p, J] + W [I ', J]}

Z = max {p | f [I, J'] = f [I, P-1] + F [p, J'] + W [I, J']}

We still need to discuss two cases, namely, z ≤ Y or Z> Y. Below we will only discuss the situation of z ≤ y, z> Y is similar.

Case 2.1, I <z ≤ y ≤ j.

Obviously, we have:

F [I, j] + F [I ', j'] <= W [I, j] + F [I, Z-1] + F [Z, j] + W [I ', j'] + F [I ', Y-1] + F [y, j']

Because W satisfies the Quadrilateral inequality, so:

F [I, j] + F [I ', J'] <= W [I, J'] + W [I', J] + F [I ', y-1] + F [I, Z-1] + F [Z, J] + F [y, j ']

Because f [I, J'] + F [I ', J] = W [I, J'] + W [I', J] + F [I ', y-1] + F [I, Z-1] + F [y, J] + F [Z, j ']

Therefore, we need to prove f [I, j '] + F [I 'J]> = f [I, j] + F [I', j '], verify f [Z, J] + F [y, j '] <= f [y, J] + F [Z, j'].

Because I <z ≤ y ≤ j, the length of the interval will become smaller and smaller in the continuous iteration, and finally it will be attributed to the previous situations.

Case 2.1, I <y ≤ z ≤ j. The verification process is omitted.

To sum up, F [I, j] satisfies the Quadrilateral inequality.

In fact, for any f [I, j] = max {f [I, K] + F [k + 1, J] + W [I, j]} {I <= k <j}. If W satisfies the Quadrilateral inequality, F also satisfies the Quadrilateral inequality.

What is the use of f as evidenced by the previous difficulties in proving that f satisfies the Quadrilateral inequality?

To prove a quadrilateral inequality, we need to prove that f satisfies the monotonicity of decision-making, that is:

S [I, J-1] ≤s [I, j] ≤s [I + 1, J], I ≤j

Where s [I, j] is the optimal decision on the interval [I, j.

When I = J, the monotonicity is obviously true. Therefore, we will only discuss the I <j. Given the symmetry, we only need to prove s [I, j] ≤ S [I, j + 1].

Make FK [I, j] = f [I, k-1] + F [K, J] + W [I, j]. To prove s [I, j] ≤ S [I, j + 1], as long as all I <k ≤ K' ≤ j and FK '[I, j] ≤fk [I, j], including: FK '[I, j + 1] ≤fk [I, j + 1].

In fact, we can prove a stronger inequality.

FK [I, j]-FK '[I, j] ≤fk [I, j + 1]-FK' [I, j + 1]

That is, FK [I, j] + FK '[I, j + 1] ≤ FK [I, j + 1] + FK' [I, j]

By using recursive defined expressions, we can find that f [K, J] + F [K', J + 1] ≤ f [K', J] + F [K, J + 1], which is the Quadrilateral inequality when K ≤ K' ≤ j <j + 1.

To sum up, when w satisfies the Quadrilateral inequality, the function s [I, j] Has monotonicity.

Therefore, we can obtain a more optimized transfer equation:

The calculated time required for the improved state transition equation is

The aforementioned method uses quadrilateral inequality to produce the monotonicity of the optimal decision, so as to reduce the number of States for each state transition and reduce the time complexity of the algorithm.

This solves the problem.

Generally, the state transition equation is like f [I, j] = opt {f [I, K] + F [k + 1, J]} + W [I, j], I <j's dynamic regulation. If W satisfies the Quadrilateral inequality, f satisfies the Quadrilateral inequality, and F has the monotonicity of decision.

By QW

Reprinted please indicate the source

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.