Password Attacker (Small)
Time limit5sMemory limit512 MB
Count length-N strings over M given symbols that use every symbol at least once, modulo 1e9+7.
- Level
Medium4 of 10
- Topics
- Combinatorics, Math
- Solved
- No attempts yet
Problem
Passwords are everywhere in daily life: cash machines, forum logins, phone unlocking, door entry. Everyone cares whether a password is safe, and attackers keep finding ways to steal one. Here is one such situation.
Eve, the attacker, wants Alice's password. Eve wipes the keyboard clean in advance. After Alice types the password and leaves, Eve collects the fingerprints left on the keyboard. Eve now knows which keys the password uses. She does not learn how many times each key was pressed, and she does not learn the order of the keystrokes.
To keep the problem simple, assume the fingerprints Eve finds sit on exactly keys. Assume also that Eve knows from another source that Alice's password is characters long. Each keystroke produces exactly one character, and Alice presses no other keys such as left, home, or backspace.
A possible password is therefore a string of length built only from the marked keys, in which each of the keys appears at least once.
For example, suppose Eve finds fingerprints on the three keys '3', '7', and '5' () and the password has four characters (). Then 3577, 3557, 7353, and 5735 are all possible, and there are 36 possible passwords in total. On the other hand 1357 is impossible because key '1' carries no fingerprint. 3355 is impossible because '7' carries a fingerprint and never appears. 357 is impossible because its length is not 4.
Count the possible passwords and report the count modulo .
Input
The first line contains the number of test cases .
Each of the next lines contains two integers and separated by a space, describing one test case.
Output
For each test case, print one line in the form Case #x: y, where is the test case number starting at 1 and is the number of possible passwords modulo .