MeeshoOA #1
Distinct Moves
HardJudge-ready
Topics (AI-labelled)SubsequencesString DP
Given a string s containing only l/r, choose a subsequence of it. Starting from x, l decreases the position by 1 and r increases it by 1; the start, every intermediate position, and the end must all lie on the finite number line 0..n, and the walk must end at y. Count distinct character sequences; the same character sequence coming from different indices counts only once. Return the count modulo 1000000007. Reflecting, staying put when out of bounds, or leaving the domain and coming back are not allowed.
Input
The first line contains s, and the second line contains n x y. Full original ranges: 1≤|s|≤1000, s contains only l/r, 0≤n,x,y≤2500. The original does not guarantee x,y≤n, and this site keeps such inputs: if the start or end is not in 0..n, there is no valid path and the answer is 0.
Output
Output an integer in 0..1000000006. All characters may be deleted, so when x=y is valid, the empty subsequence contributes 1; for n=0,x=y=0 the answer is 1, and for any other out-of-domain endpoint the answer is 0. This interpretation follows the original's finite number line and deletion of zero or more elements, and does not additionally require a non-empty subsequence.
Example 1
Input:
rr
2 0 1
Output:
1
Example 2
Input:
lr
1 0 0
Output:
1
Example 3
Input:
rl
1 0 0
Output:
2
Example notes
All three public examples were derived by this site. For rr from 0 to 1, the string r counts only once, not as two index choices; for lr from 0 back to 0, lr goes out of bounds, so only the empty string is valid and the answer is 1; for rl from 0 back to 0, both the empty string and rl are valid, so the answer is 2.
Editorial
Loading solution…