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?
- A. Bitmask DP over subsets is O(2^n * n^2), which is feasible in C++ for n = 20
- B. Bitmask DP is O(n!) and infeasible for n = 20
- C. Bitmask DP needs O(n^3) per state
- 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
- Problem: Which claim about a binary search over a rotated sorted array (no duplicates) finding the minimum element is correct?
- Problem: How many pairs (i < j) of a = [1, 2, 4, 5, 7, 8] have a[i] - a[j] divisible by 3? Run the code. python a = [1, 2, 4, 5, 7, 8]…
- Problem: What is the minimum number of meeting rooms needed for intervals [0,30], [5,10], [15,20]? Run the sweep-line code. python iv =…
- Problem: How many inversions (pairs i < j with a[i] > a[j]) does a = [2, 0, 2, 1, 1, 0] have? Run the code. python a = [2, 0, 2, 1, 1, 0]…
- Problem: How many integers x in [1, 50] are perfect sixth powers (x = y^6 for an integer y)? Run the code. python print(sum(1 for x in…
- Problem: Merging ropes of lengths 2, 3, 4 costs the sum of the two lengths merged each time, always merging the two shortest. What is the…