Polynesiaglot (Large)
InterviewTime limit5sMemory limit512 MB
Count length-L words over C consonants and V vowels where every consonant is followed by a vowel, modulo 1e9+7.
- Level
Easy3 of 10
- Topics
- Dynamic programming, Combinatorics
- Solved
- No attempts yet
Problem
Ursula likes building constructed languages. Today she started one inspired by real Polynesian languages. So far she has fixed two rules.
- Every word is made of letters. A letter is either a consonant or a vowel.
- A consonant inside a word must be immediately followed by a vowel.
For example, in a language where a is the only vowel and h is the only consonant, a, aa, aha, aaha, and haha are valid words, while h, ahh, ahah, and ahha are not. The rule blocks a consonant after a consonant, and it also blocks a word that ends in a consonant.
Ursula's new language has different consonants and different vowels. How many different valid words of length are there? The answer can get very large, so report it modulo the prime .
Input
The first line contains the number of test cases . Each of the next lines contains three integers , , and , separated by spaces.
Limits
Output
For each test case, print one line in the form Case #x: y, where is the test case number starting from 1 and is the number of valid words of length , modulo .
Hint
In the first test case of the first example, suppose a is the only vowel and h is the only consonant. The valid words of length 4 are aaaa, aaha, ahaa, haaa, and haha, so there are five of them.
In the second test case of the same example, suppose the vowels are a and e and h is the only consonant. The valid words of length 2 are aa, ae, ea, ee, ha, and he, so there are six of them.