Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Nice problem. I've found a solution in O(n·m·8^m), which seems to be sufficent.</p> <ol> <li><p>Focus on the border between the first and the second row. There are 2^m possibilities (outgoing line or not, for each side). This will be the upper border line, the lower border line will be no connection at each side.</p></li> <li><p>For each pair of lower border line and upper border line (which will be 2^m·2^m = 4^m pairs), calculate each row that fits in. If you come from the left, you are given the left side, the top side and the bottom side, so you only have 2 possibilities. If the tile you look at is fixed in the map, check that it fits in and abort otherwise. Call this recursively and you get 2^m rows each or 4^m*2^m=8^m in total.</p></li> <li><p>While the last step was pure brute force, we use DP this time. Safe the tuple (border, bricks used, row) in an array of arrays. array[0] will contain a single tuple (empty-border, no-brick-used, nothing). array[n] contains all 8^m generated rows in row n (starting at 1) combined with each item in array[n-1] it fits on (i.e. the border of the item is the same as the lower border of the row) Notice that if you smartly combine this condition with the loop in step 2, this costs you nothing.</p></li> <li><p>Remove all tuples which needs more bricks of one sort than available and sort the array. Then continue on step 2 until all rows are handled.</p></li> <li><p>If you have finished, check in array[n] for the tuple (empty-border, all-bricks-used, row). Since your task description implies that it exists, print out its row. Then look at the lower border of row and search for that in array[n-1] and print it too, and so on.</p></li> </ol> <p>Hope you understand my English.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload