Блог пользователя BryantMark

Автор BryantMark, 12 лет назад, По-английски

What kind of algorithm can be used to solve this problem? http://poj.org/problem?id=3133 I suppose that dynamics and bit mask shall be adopted. I could not figure out how to express the accurate state of it. Thanks anyway

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
12 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I guess mincost flow is much easier for this problem than dp

»
12 лет назад, # |
Rev. 2   Проголосовать: нравится +2 Проголосовать: не нравится

Yes,we use DP with bitmask to solve this problem.We go through the map from top to bottom,and left to right.Let L be the border of cells we have visited and we haven't visited.So there is m+1 segment on L.One vertical segment,and m horizontal ones.State k contains 2*m+2 bits,because we need 2 bits to represent the state of a segment.

0:This segment isn't connected to a path.

1:This segment is connected with a "2" path.

2:This segment is connected with a "3" path.

dp[x][y][k] means the min length of the path after we visited cell (x,y) ,with the current state of L is k. Since there are so many states and lots of them are invaild,I used hash and queue. So the answer is dp[n][m][0].

Sorry,I'm not good at expressing,it is some kind of DP algorithm called "Plug DP" or "DP based on connectivity". If you you still have questions,just ask me or refer to my code here.