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

Автор shawsk, история, 15 месяцев назад, По-английски

Given a number line from 0 to n and a string denoting a sequence of moves, determine the number of subsequences of those moves that lead from a given point x to end at another point y.

Moves will be given as a sequence of 'l' and 'r' instructions:

'l' → Left movement (j → j - 1)
'r' → Right movement (j → j + 1)

Example Input:

Number line: 0 to 6
Moves sequence: "rrlrlr"
Start position: x = 1
End position: y = 4

Output:

3 (There are 3 subsequences that reach from 1 to 4)

Notes: 0 and n are the lower and upper limits of number line, you cannot exceed those. The answer should be returned modulo (10⁹ + 7).

Can anyone help with this.

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

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

well brute is easy but cant think of optimal solution.

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Where does this question come from, I want to know.

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

How large is $$$n$$$? There is obviously $$$O(n^3)$$$ DP, but I doubt n is only 1e3.

»
7 месяцев назад, скрыть # |
Rev. 5  
Проголосовать: нравится 0 Проголосовать: не нравится

we can dfs and find the ans and use a visited (index , pos , hash) for distinct values ?