Welcome to Code Jam (Small)
InterviewTime limit5sMemory limit512 MB
Count how many ways the 19-character phrase "welcome to code jam" appears as a subsequence of the input line, and print the last four digits.
- Level
Medium4 of 10
- Topics
- Dynamic programming, String
- Solved
- No attempts yet
Problem
Skim a long paragraph and you can build the phrase "welcome to code jam" out of it: find a 'w', then find an 'e' later on, then an 'l' after that, and so on. The same paragraph gives many different ways to do it, depending on which letters you pick.
Given one line of text, count how many ways "welcome to code jam" appears in it as a subsequence. Formally, let be the input string and let = "welcome to code jam". Count the index sequences with such that concatenating gives . The length of is 19 including its spaces, and each space of must also be matched by a space of the input.
The count can be huge, so report only its last four digits.
Input
The first line contains the number of test cases . Each of the next lines contains one test case, a single line of text made of lower-case English letters and spaces. No line starts with a space and no line ends with a space.
Limits
- Each line is at most 30 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 dddd is the last four digits of the answer. If the answer has fewer than four digits, pad it with leading zeros so that it is exactly four digits long.