Crypto
Time limit2sMemory limit512 MB
Count permutations of 1..N whose window-product multiset, taken as the K smallest primes, has exactly P distinct values, modulo 1e9+7.
- Level
Hard9 of 10
- Topics
- Combinatorics, Number theory, Dynamic programming, Implementation
- Solved
- No attempts yet
Problem
Pesho is encrypting a sequence of N numbers where each integer from 1 to N appears exactly once. He uses the following algorithm:
- Replace each initial number X with the Xth prime number.
- Choose a random positive integer K, not greater than N.
- Consider all subsequences of consecutive elements. For each subsequence with at least K elements, write down the product of the smallest K numbers.
- Let P be the number of distinct products written in the previous step.
- The code is "N K P".
Let us see how Pesho should encrypt the sequence {4, 1, 3, 2}:
- The first 4 prime numbers are 2, 3, 5 and 7. In the initial sequence he replaces
- 4 with the fourth prime number, which is 7;
- 1 with the first prime number, which is 2;
- 3 with the third prime number, which is 5;
- 2 with the second prime number, which is 3.
Pesho obtains the new sequence {7, 2, 5, 3}.
- He chooses a random number K. Say K=2.
- All contiguous subsequences are:
{7}, {2}, {5}, {3}, {7, 2}, {2, 5}, {5, 3}, {7, 2, 5}, {2, 5, 3}, {7, 2, 5 ,3}
Pesho removes all subsequences with less than K=2 elements and for each of the rest he computes the product of the smallest K=2 elements.
- {7, 2} 2.7 = 14
- {2, 5} 2.5 = 10
- {5, 3} 3.5 = 15
- {7, 2, 5} 2.5 = 10
- {2, 5, 3} 2.3 = 6
- {7, 2, 5 ,3} 2.3 = 6
He writes the numbers {14, 10, 15, 10, 6, 6}
- There are four distinct numbers {6, 10, 14, 15}, thus P = 4.
- The code is "4 2 4".
Pesho quickly figured out that the algorithm is much better than he expected. He cannot always decrypt the code unambiguously.
Write a program crypto, which given a code calculates the number of possible initial sequences. Find the answer modulo 1 000 000 007.
Input
The first line contains the positive integers N, K and P.
Output
Print the number of possible initial sequences with code "N K P". Print the answer modulo 1 000 000 007.
Constraints
- 1 ≤ K ≤ N ≤ 400
- 1 ≤ P ≤ 1 000 000 000
Examples
Sample 1
Input:
3 2 3
Expected output:
2
Sample 2
Input:
4 2 4
Expected output:
12