Permutations and cycles P99557


Statement
 

pdf   zip

Given two natural numbers nn and kk, let f(n,k)f(n, k) denote the number of permutations with nn elements, and such that there are exactly kk cycles, all them of length at least 2. Implement a dynamic programming code to compute f(n,k)f(n, k).

Input

Input consists of several cases, each with two natural numbers nn and kk. You can assume 2n10002 \le n \le 1000 and 1kn/21 \le k \le \lfloor n/2 \rfloor.

Output

For every case, print f(n,k)f(n, k). Because that number can become very large, use @long long@’s and make the computations modulo 109+710^9 + 7.

Hint

You can compute f(n,k)f(n, k) just adding two “recursive calls”.

Public test cases
  • Input

    2 1
    3 1
    4 1
    4 2
    5 1
    5 2
    20 5
    100 10
    1000 1
    1000 2
    1000 500
    

    Output

    1
    2
    6
    3
    24
    20
    796437723
    673801497
    756641425
    592422688
    164644882
    
  • Information
    Author
    Enric Rodríguez
    Language
    English
    Translator
    Salvador Roura
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++