Cowmpetency
Time limit2sMemory limit1024 MB
Count the score sequences of N cows, each score from 1 to C, that satisfy each pair where cow h is the first with a score above cows 1 through a, modulo 10^9+7.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Combinatorics, Prefix sum
- Solved
- No attempts yet
Problem
Farmer John is hiring a new herd leader for his cows. He has interviewed cows for the position (). After each interview, he gave the candidate a cowmpetency score, an integer from to (), which reflects that cow's leadership ability.
Farmer John has forgotten every cowmpetency score. He does remember pairs (): cow was the first cow with a strictly greater cowmpetency score than cows through , so .
You are given the pairs. Count the sequences of cowmpetency scores that are consistent with this information. At least one such sequence is guaranteed to exist. Output the count modulo .
Input
The first line contains , , and .
Each of the next lines contains a pair . All are distinct.
Output
Print the number of consistent sequences of cowmpetency scores modulo .