Counting Distinct Subsequences
Time limit1sMemory limit512 MB
Count the distinct subsequences of a string, including the empty string, for up to 10,000 test cases.
- Level
Medium6 of 10
- Topics
- Dynamic programming, String, Math
- Solved
- No attempts yet
Problem
Let be a string. Every string of the form with and is called a subsequence of . The empty string, of length 0, is also a subsequence of . For example, the string ioi has 7 distinct subsequences: the empty string, i, o, ii, io, oi, and ioi.
Given a string , find the number of distinct subsequences of .
Input
The first line contains the number of test cases (). Each of the next lines contains one string . consists only of uppercase English letters, lowercase English letters, and the digits 0 to 9, and its length is between 1 and 1,000 inclusive. Uppercase and lowercase letters are different characters.
Output
For each test case, print the number of distinct subsequences of on its own line. The empty string is counted. Every input string is guaranteed to have an answer of at most .