#P3867. [TJOI2009] 排列计数

    ID: 2805 远端评测题 1000~10000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>递推2009各省省选O2优化枚举,暴力天津

[TJOI2009] 排列计数

Description

We know there are N!N! permutations of the NN numbers 1,2,...,N1,2,...,N. Your task is to count how many of these permutations have the property that the difference between any two adjacent numbers does not exceed KK.

Since the result may be large, output the answer modulo 109+710^9+7.

Input Format

The input contains a single line with two space-separated integers: N,KN, K.

Output Format

Output the number of valid permutations modulo 109+710^9+7.

4 2
12

Hint

On 30% of the testdata, N12N \le 12.

On 100% of the testdata, N50N \le 50, K4K \le 4.

Time limit per test point: 10 seconds.

Translated by ChatGPT 5