Knights of the Round Table
Time limit3sMemory limit256 MB
Count distinct final seat assignments over all entry orders when each remaining knight walks clockwise to the first free seat, modulo 1e9+7.
- Level
Hard8 of 10
- Topics
- Combinatorics, Math
- Solved
- No attempts yet
Problem
K knights sit at seats 1..K around a circle. The first D distracted knights already sat (knight assigned seat A is on seat B). Each remaining knight enters, tries his own seat, and if it is taken walks clockwise to the first free seat. Count distinct final seatings over all entry orders of the remaining knights, modulo 10^9+7.
Input
Several test cases. Each has K, D, then D lines with A and B meaning the knight assigned seat A sat on seat B.
Output
For each test case, print the number of distinct final distributions modulo 10^9+7.