Data Structures & AlgorithmsHardCodeforces Div2 D · bitmask DP

Problem: Which statement about bitmask DP for a Hamiltonian path problem on n = 20 vertices is correct in the standard sense?

  1. A. Bitmask DP over subsets is O(2^n * n^2), which is feasible in C++ for n = 20
  2. B. Bitmask DP is O(n!) and infeasible for n = 20
  3. C. Bitmask DP needs O(n^3) per state
  4. D. It cannot represent subsets of 20 items

Correct answer: A. Bitmask DP over subsets is O(2^n * n^2), which is feasible in C++ for n = 20

There are 2^20 * 20 states with n transitions each, roughly 4 * 10^8 operations, which fits a 2-second limit with tight code. Claiming O(n!) is the trap.

More Coding Interview Problems questions

Exams that ask this topic