Counting welcome to code jam subsequences
Time limit5sMemory limit512 MB
Count subsequences of each input text that spell the 19-character target string, printed as the last four digits.
- Level
Medium5 of 10
- Topics
- Dynamic programming, String
- Solved
- No attempts yet
Problem
Count how many times the 19 character string welcome to code jam appears as a subsequence of a given text.
To be precise, let be the text and consider an index sequence with . Count the sequences for which concatenating , , ..., in that order gives exactly welcome to code jam. Two sequences that pick the same letters from different positions count separately.
The answer can be huge, so print only its last four digits.
Input
The first line contains the number of test cases . Each of the next lines contains one test case as a single line of text. Every line consists of lowercase English letters and spaces only, and never starts or ends with a space.
- Each line is between 1 and 500 characters long.
Output
For each test case, print one line in the form Case #x: dddd, where is the test case number starting from 1 and is the last four digits of the answer. If the answer has fewer than four digits, pad it with leading zeros so that exactly four digits are printed.