Know your ABC's
InterviewTime limit2sMemory limit1024 MB
Count the strings with a A's, b B's, and c C's where no two adjacent letters match, modulo 10^9 + 7.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Combinatorics
- Solved
- No attempts yet
Problem
UCF has started running a pre-school where it teaches all the students their ABCs. Every block the kids play with shows one of the letters A, B, or C. The kids like arranging the blocks, but they dislike any arrangement where two identical letters sit next to each other.
For example, if a kid has 2 A blocks, 3 B blocks, and 1 C block, BACBAB is a valid arrangement. CBABBA is not valid because the letter B appears twice in a row.
The teacher wants to know how many different valid orders the blocks can be arranged in. Two arrangements are different if they have a different letter in some position.
Input
A single line contains three integers , , and (, , ), the number of blocks showing A, B, and C.
Output
Print the number of valid arrangements of all the blocks in a row, with no two consecutive blocks showing the same letter, modulo .