Given a string, count all distinct subsequences (not substrings).
As defined previously, a subsequence is a collection of characters from the string (they don't have to be contiguous).
For example, for the string aba
, there are 6 distinct subsequences: (a
, b
, aa
, ab
, ba
, aba
).
Input Specification
The string, on one line. It will consist only of lowercase letters.
It will be no longer than characters long (this is easier than all substrings!).
Output Specification
The number of distinct subsequences.
Note that this number may be ridiculously large, so print it .
Comments
I think there is an error in the question, because it states: For example, for the string aba, there are 6 distinct subsequences: (a, b, aa, ab, ba, aba). But wouldn't 'aab' and 'baa' also be distinct subsequences?
No. The characters still have to be in order. See https://en.wikipedia.org/wiki/Subsequence for a maybe better definition.