Scar Prepares an Attack
Time limit2sMemory limit1024 MB
Count the ways to pick a nonempty subsequence of each hyena's genotype so that each chosen birth genotype is stronger than the next, modulo 1e9+7.
- Level
Hard8 of 10
- Topics
- Dynamic programming, String, Bit manipulation, Sorting
- Solved
- No attempts yet
Problem
Scar is preparing an army of hyenas for an attack. hyenas came to the selection. Scar wants to pick the most capable ones, those born with a natural talent.
Each hyena has a genotype, which is a sequence of genes. Genes are denoted by lowercase Latin letters.
Each hyena's genotype at birth was some nonempty subsequence of its current genotype. During its life, an arbitrary number of arbitrary genes were inserted at various places in the genotype, and it took its current form.
We say genotype is stronger than genotype if there is an index such that for all and comes earlier in the alphabet than . If for all , the genotype with fewer genes is stronger.
Scar wonders what the birth genotypes could have been. It is known that the birth genotype of the -th hyena was stronger than the birth genotype of the -th hyena. Count the number of possible sets of birth genotypes that satisfy all these conditions, modulo .
Input
The first line contains (), the number of hyenas. Each of the next lines contains the current genotype of the -th hyena. Each string has length at most 13.
Output
Print the number of sets of birth genotypes that satisfy all conditions, modulo .