The well-known Parquet Problem asks the following: Given an N x M board, find the number of ways to tile it using only 1 x 2 or 2 x 1 tiles. I’m interested in the DP approach that calculates the answer in O(2^N * NM), as shown on this USACO Guide page, but I can’t understand the DP state that is used.
My understanding of their DP-state is that dp[i][j][mask] = the number of ways to tile the grid so that basically columns 0 to j−2 are all completely filled. Meanwhile, column j−1 may not be completely filled, but must be filled from rows 0 to ii. And mask represents whether or not rows 0 to i in column j, and rows i+1 to N−1 in column j−1, are filled.
Here’s the explanation that appears on the USACO Guide article:
(For the 3rd bullet point, I think the k-th bit should correspond to the k-th row, not the k-th column. Additionally, I think the bitmask should be reversed, because 1 << i represents row i, so if we go from the top row to the bottom we should actually be reading 10100_2 backwards I think)
This explanation fits with the picture. But, when I actually run the provided program, I get DP-values that don’t seem to agree with my understanding. Mainly, I don’t understand what the DP-state means conceptually when j=0 . For instance, one value we get is that dp[1][0][0011]=1. Based on my understanding, this basically represents the number of ways to tile only the leftmost-column, and only the bottommost two cells, so 1 does make sense here.
But if we look further, we see that dp[1][0][1100]=0, not 1! Shouldn’t this just equal 1 as well, since it represents the number of ways to tile only the top two squares of the leftmost column?
Overall, I feel that my current confusion stems from an overall misunderstanding of the DP state used. If someone could give an explanation of the DP-state, I would greatly appreciate it!