Polynesiaglot (Small 1)
InterviewTime limit5sMemory limit512 MB
Count length-L words over C consonants and V vowels in which each consonant is directly followed by a vowel, modulo 1000000007.
- Level
Easy3 of 10
- Topics
- Dynamic programming, Combinatorics
- Solved
- No attempts yet
Problem
Ursula likes to build constructed languages. Today she starts one inspired by real Polynesian languages, and so far she has fixed two rules.
- Every word is made of letters. Each letter is a consonant or a vowel.
- Every consonant in a word must be immediately followed by a vowel.
For example, in a language whose only vowel is a and whose only consonant is h, the words a, aa, aha, aaha, and haha are valid, while h, ahh, ahah, and ahha are not. The second rule forbids a consonant followed by another consonant, and it also forbids a word that ends with a consonant.
Ursula's language has different consonants and different vowels. Count the valid words of length . The answer can be very large, so print 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 of the form Case #x: y, where x is the test case number starting from 1 and y is the number of valid words of length , modulo .
Note
Take , , . Write the vowel as a and the consonant as h. The valid words are aaaa, aaha, ahaa, haaa, and haha, so the answer is 5.
Take , , . Write the vowels as a and e and the consonant as h. The valid words are aa, ae, ea, ee, ha, and he, so the answer is 6.