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

Автор sudipta550, история, 4 года назад, По-английски

I need help in the tiling problem.This the problem I cannot understand how to count the total no of dominos in the case of blue colors. Should I write two dp tables one is the row-major matrix(for red) and the other is the column-major matrix(for blue)? I cannot understand how to write. Please help...

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

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

112847614 You can look at this submission, it is quite neat.

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

    Thanks for your response. ****This is going above my head. Can you please give me some intuition behind this solution?

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

      dp[i] is the contribution to the answer if we have i consecutive white cells in a row/column.

      Let's take the case of row. If last cell if blue then it's equivalent to dp[i-1]. If last cell is red but 2nd last cell is blue it is equivalent to dp[i-2]. And the remaining case, if both last 2 cells are red, it is equivalent to dp[i-2] and a tile on last 2 positions. That tile will contribute for all the 1<<(i-2) states of the previous cells.

      Hence, dp[i]=dp[i-1]+2*dp[i-2]+a[i-2] where a[x]=2^x.

      That was the main intuition behind the solution.