Stack Block Algorithm

enter image description here

I'm getting a little stuck trying to solve this problem. The main source of confusion comes from the fact that you do not know when to remove the box.

Here is my approach:

. , , , . , , . , , , . , . , , , . , ? , , .

, , , , .

+4
2

, .

, , . . . ? ( ) , ( "", "" ", , ).

, ( , , ). , . , . !

+1

, , .

[x1, x2, x3, ...] [y1, y2, y3, ...] :

  • case (A): x1 y1: ,
  • case (B): x1 is - y1 : y
  • case (C): y1 is - x1 : x
  • case (D): x1 y1 , ; : (D1) flip x1 [x2,...] [y2,...], (D2) x1 [x2, ...] [y1, ...]. (D1) (D2) , .

: (D3) y1 x [x1,...] [y2,...] , ( B).

( ):

int min_moves(int i, int j);

x[i], x[i+1], ... y[j], y[j+1], ..., x y - , , x[i] y[i] - i>m.

min_moves(i, j) min_moves(i+1, j+1) ( A + D1), min_moves(i+1, j) ( D2). B C , x y.

+1

Source: https://habr.com/ru/post/1534673/


All Articles