Dictionary
Time limit4sMemory limit512 MB
Count the ways to replace each ? in n sorted words with lowercase letters so the words stay in strictly increasing lexicographic order, modulo 1,000,000,007.
- Level
Medium6 of 10
- Topics
- Dynamic programming, String, Recursion
- Solved
- No attempts yet
Problem
Snuke's dictionary contains distinct words . Each word consists of English lowercase letters. The words are sorted lexicographically, that is, . Some characters in the dictionary are unreadable, so they were replaced with ?. Count the ways to replace each ? with an English lowercase letter so that the result is a valid dictionary. Print the count modulo 1,000,000,007.
Input
The first line contains an integer (). Each of the next lines contains a word (). Each character of is either an English lowercase letter or ?.
Output
Print the answer.