Usaco 3.3.3 packing rectangles (packrec ))

Source: Internet
Author: User

Report: http://starforever.blog.hexun.com/2097115_d.html

 

Because there are only four squares, the order and placement direction (horizontal or vertical) of each square are enumerated. The placement method is only the six basic modes given by the question, calculate the minimum area in different modes and update the optimal solution.

 

 

 

 

4th and 5 are essentially the same ., The minimum area for different modes is as follows:

Set W1, W2, W3, and W4 to the horizontal length of the four blocks. H1, H2, H3, and H4 indicate the vertical length of the four blocks. W, h indicates the minimum value.

1: W = W1 + W2 + W3 + W4; H = max (H1, H2, H3, H4)

2: W = max (W1 + W2 + W3, W4); H = max (H1, H2, H3) + h4

3: W = max (W1 + W2, W3) + W4; H = max (H1 + H3, H2 + H3, H4)

4: W = W1 + W2 + max (W3, W4); H = max (H1, H3 + H4, H2)

5: H = max (H1 + H3, H2 + h4)

For W, we can divide it into the following four forms:

 

 

(1): h3> = h2 + H4; W = max (W1, W3 + W2, W3 + W4)

(2): h3> H4 and H3 <H2 + H4; W = max (W1 + W2, W2 + W3, W3 + W4)

(3): H4> H3 and H4 <H1 + H3; W = max (W1 + W2, W1 + W4, W3 + W4)

(4): H4> = H1 + H3; W = max (W2, W1 + W4, W3 + W4)

*: H3 = H4 (not shown in the figure); W = max (W1 + W2, W3 + W4)

Record the optimal solution with an array, and finally sort the output.

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.