Overview
In problems with small constraints (e.g., N ≤ 20), we can represent a subset of items as bits in an integer. This is called a bitmask.
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Represent small sets using integers (bitmasks) to solve problems like the Assignment Problem or TSP.
In problems with small constraints (e.g., N ≤ 20), we can represent a subset of items as bits in an integer. This is called a bitmask.
We want to assign N workers to N tasks with minimum cost. The mask represents which tasks are already assigned.
If task j is not in the mask `(mask & (1 << j) == 0)`, we transition to `mask | (1 << j)` by assigning the next available worker to task j.
The number of set bits in the mask equals the number of workers we've already assigned. We don't need a separate dimension for workers.