Skip to content
Embercode
✕
DP optimisationsQuick quiz

Bitmask and digit DP

8 questions. Covers Digit DP.

Questions 1 to 5 of 8

  1. 1. An AI tool wrote this for 20 items. For each mask, it loops over every submask s of that mask, and it does a constant amount of work per pair. ``cpp for (int mask = 0; mask < (1 << n); mask++) for (int s = mask; ; s = (s - 1) & mask) { total += f[s]; if (s == 0) break; } `` How many (mask, submask) pairs does this visit when n = 20?
  2. 2. Using the same submask loop, how many (mask, submask) pairs does it visit when n = 18?

    Type a number.

  3. 3. Which statements about the tight flag in digit DP are true?

    Pick every answer that is true.

  4. 4. An AI tool wrote a digit DP to count x from 1 to N = 130 with digit sum divisible by 3 and at most one zero. On this input it prints 330, but the answer is 43. The tight flag is never passed to the next position, so every 3-digit string counts. Which numbers are wrongly counted?
  5. 5. Another AI digit DP pads each number to three digits, so 5 is read as 005. It counts zeros in the padding, and on N = 130 it prints 36 instead of 43. Which change fixes the bug?

5 question(s) left on this page.

Typed answers ignore extra spaces and, for most questions, capital letters.