What goes in the blank?
# bitmask DP (travelling salesman): visit city v next
for v in range(n):
if mask & (1 << v):
continue # already visited
nmask = mask ____ (1 << v)
dp[nmask][v] = min(dp[nmask][v], dp[mask][u] + w[u][v])
Answer: |
OR sets bit v, adding city v to the visited set. Because the bit is known to be 0 here, ^ and + give the same result, but | is the idiom.
Play Problem Solving ▸