Overview
Also known as "Broken Profile DP". If you are filling a grid column by column, the boundary between the filled and unfilled sections can be jagged.
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Use an integer bitmask to represent a complex boundary state (like a jagged edge in a grid tiling problem) allowing O(1) state transitions.
Also known as "Broken Profile DP". If you are filling a grid column by column, the boundary between the filled and unfilled sections can be jagged.
Since the grid height `M` is usually very small (e.g., M ≤ 15), we can represent the jagged boundary as an `M`-bit integer. `1` means filled, `0` means empty.
From `dp[col][mask]`, we try placing blocks that fill the `0`s in the current `mask`. Any blocks that spill over into the NEXT column will create the `next_mask`.
We usually want to tile the entire grid perfectly. This means we want the answer at `dp[N][0]` (after processing all N columns, 0 bits spill over into the void).