DSUBSEQ - Distinct Subsequences

Given a string, count the number of distinct subsequences of it ( including empty subsequence ). For the uninformed, A subsequence of a string is a new string which is formed from the original string by deleting some of the characters without disturbing the relative positions of the remaining characters.
For example, "AGH" is a subsequence of "ABCDEFGH" while "AHG" is not.


First line of input contains an integer T which is equal to the number of test cases. You are required to process all test cases. Each of next T lines contains a string s.


Output consists of T lines. Ith line in the output corresponds to the number of distinct subsequences of ith input string. Since, this number could be very large, you need to output ans%1000000007 where ans is the number of distinct subsequences.




Constraints and Limits

T ≤ 100, length(S) ≤ 100000
All input strings shall contain only uppercase letters.

hide comments
prasoonbatham: 2017-01-14 15:17:38

Always check output before submitting. Cost me 1 wa. :(
Great question though!! Just observe the pattern :)

kira28: 2017-01-07 19:53:04

4 WAs due to MOD :/

madhavgaba: 2016-12-30 12:31:23

@VINAYAK if ur answer is negative.....just add MOD to ur answer

vinayak_1997: 2016-12-29 14:05:45

Why will modulo here give negative answer?

Last edit: 2016-12-29 14:31:38
m_alhussein_96: 2016-08-19 06:59:29

why I can't solve it top-down ?

Avik Sarkar: 2016-08-16 09:50:23

Be Careful With MOD .. The subtraction you are doing to remove the multiple occurrences may cause a negative result . That's why you have make it Positive .

singh1495: 2016-06-22 06:52:59

ACCEPTED in first go such a nice ques... takes time but nice dp

akshayvenkat: 2016-05-29 18:04:54

what is the maximum length of input string?

kshubham02: 2016-05-26 21:43:02

Thank you @PRANJIT BHARALI! Your comment saved me! I had totally forgotten about the MOD, got WA and was going mad testing different self-made test cases.
"be careful with MOD ...!!!"

praval_singhal: 2016-05-17 15:23:51

Misread Max String Length as 10,000. Got SegFault. AC in 2nd Attempt. :)

Added by:Ajay Somani
Time limit:0.245s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: C++ 5
Resource:CodeCraft 08, Problem Setter: Jin Bin