Блог пользователя hydro_lyte

Автор hydro_lyte, история, 5 лет назад, По-английски

The question is- We are given two integers L and R. We are required to determine the count of special numbers ranging in between L and R. If the binary representation of X contains a pattern 101, then X is called special number. Constraints- 1 ≤ L ≤ R ≤ 10^18

We have to print the total count of special numbers in the range [L,R]

  • Проголосовать: нравится
  • +4
  • Проголосовать: не нравится

»
5 лет назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

Use the same DP that you use for digit DP, and add two extra states: one to represent if this pattern has occurred in the binary representation so far (0 or 1), and the second to represent the size of the prefix of the pattern that is currently matching (0, 1, 2, or 3).