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?
- A. O(n!)
- B. O(n^3)
- C. O(2^n * n)
- 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
- Problem: A string of length n is built using the operation 'append the reverse of the current string'. Starting with 'a', the length after…
- Problem: Which statement about Dijkstra's algorithm using a binary heap with lazy deletion (pushing duplicate entries and skipping stale…
- Problem: What does the following print? python x = 5 print(x << 3 | x >> 1, x & 6, x ^ 3)
- Problem: For the string 'mississippi', what is the number of distinct substrings of length 2 that occur at least twice? Run the code…
- Problem: How many Armstrong numbers (numbers equal to the sum of their digits each raised to the power of the digit count) lie in [1…
- Problem: In how many ordered ways can 10 be written as a sum of parts from {1, 2, 3}, where the order of the parts matters? Run the code…