Counting permutations

2.8

6 votes
Special Numbers, Counting, Mathamatics, Math, C++
Problem

You are given two integers n and m. You are required to find the number of permutations of n such that for each i the |aii|m where |xy| denotes the absolute difference between x and y.

Example:

Here, n=4 and m=3, therefore, the valid permutations are [2 4 1 3], [1 3 4 2], and so on. The invalid permutations for the same are [4 1 3 2], [3 2 4 1], and so on.

Note: As the number can be large, print answer modulo 1000000007.

Input format

The first line contains two integers n and m.

Output format

Print one integer denoting the number of permutations that are valid. As the number can be very large, print answer modulo 1000000007.

Constraints

 2n1e31m<n

Sample Input
4 3
Sample Output
14
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Valid Permutations:

1 2 3 4 
1 2 4 3 
1 3 2 4 
1 3 4 2 
1 4 2 3 
1 4 3 2 
2 1 3 4 
2 1 4 3 
2 3 1 4 
2 4 1 3 
3 1 2 4 
3 1 4 2 
3 2 1 4 
3 4 1 2 
 

Invalid Permutations

2 3 4 1 
2 4 3 1 
3 2 4 1 
3 4 2 1 
4 1 2 3 
4 1 3 2 
4 2 1 3 
4 2 3 1 
4 3 1 2 
4 3 2 1 

Editor Image

?