Algorithms and Data Structures · Senior · Question 26 of 75

What does bitmask DP use as its state?

Explanation

With n up to about 20, subsets fit in an integer: mask | (1 << i) adds element i, mask & (1 << i) checks it. States like dp[mask][last] solve TSP and assignment problems in O(2ⁿ × n²).

Further reading

Problem with a question

Algorithms and Data Structures · Senior · question 26

Test yourself

Take the Algorithms and Data Structures · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz