Data Structures & AlgorithmsVery hardICPC regional · bitmask DP

Problem: Consider a DP over subsets for assigning n jobs to n workers (cost matrix given), with state = mask of assigned jobs and transition over the next worker. What is the complexity?

  1. A. O(n!)
  2. B. O(n^3)
  3. C. O(2^n * n)
  4. D. O(n * 2^n * 2^n)

Correct answer: C. O(2^n * n)

The worker index equals popcount(mask), so each mask has one job to assign per transition, giving 2^n states with n transitions each. Trying all permutations costs O(n!), which is the trap.

More Coding Interview Problems questions

Exams that ask this topic