Dynamic Programming21 sections · 916 units
Open in Course

Counting Tilings - Filling a Column

Recursive placement

To fill column cc with profile cur_maskcur\_mask, process rows 00 to n1n-1. If bit ii is set, that cell is already occupied (skip). Otherwise, you must fill it. Two choices: place a vertical tile (occupies current and next column, setting bit ii in next_masknext\_mask) or horizontal tile (occupies current column only, but row i+1i+1 must also be empty and gets filled).

This recursive function tries all valid placements and accumulates ways to reach each next_masknext\_mask. Only when all rows are processed does next_masknext\_mask become a valid next profile.