Permutations and cycles (1)

Write a program to count the number of permutations of {1,,n}\{1, \ldots, n\} with exactly kk cycles, where 1kn1 \le k \le n.

For instance, of the six permutations of {1,2,3}\{1, 2, 3\}, we have:

Input

Input consists of several cases, each with nn and kk, such that 1kn10001 \le k \le n \le 1000.

Output

For every case, count the number of permutations of {1,,n}\{1, \ldots, n\} with kk cycles. As the result can be very large, make the computations modulo 108+710^8 + 7.

Observation

Let cc be the number of cases. The expected solution has total cost O(10002+c)O(1000^2 + c). You can get up to 80 points with test cases where n100n \le 100, with a solution with cost O(1003+c)O(100^3 + c).

Problem information

Author: Unknown
Translator: Salvador Roura

Generation: 2026-01-25T11:19:11.851Z

© Jutge.org, 2006–2026.
https://jutge.org