Problem:
Score : 600 points

Problem Statement

Let us define the oddness of a permutation p = {p_1,\ p_2,\ ...,\ p_n} of {1,\ 2,\ ...,\ n} as \sum_{i = 1}^n |i - p_i|.

Find the number of permutations of {1,\ 2,\ ...,\ n} of oddness k, modulo 10^9+7.

Constraints

All values in input are integers.

1 \leq n \leq 50

0 \leq k \leq n^2

Input

Input is given from Standard Input in the following format:

n k

Output

Print the number of permutations of {1,\ 2,\ ...,\ n} of oddness k, modulo 10^9+7.

Sample Input 1

3 2

Sample Output 1

2

There are six permutations of {1,\ 2,\ 3}. Among them, two have oddness of 2: {2,\ 1,\ 3} and {1,\ 3,\ 2}.

Sample Input 2

39 14

Sample Output 2

74764168

Solution in Java (OpenJDK 11.0.6) (judge verdict: Accepted)

import java.util.Scanner;

public class Main {
    static final int MODULUS = 1_000_000_007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int k = sc.nextInt();

        System.out.println(solve(n, k));

        sc.close();
    }

    static int solve(int n, int k) {
        int[][][] wayNums = new int[n + 1][n + 1][k + 1];
        wayNums[0][0][0] = 1;
        for (int i = 1; i <= n; ++i) {
            for (int j = 0; j <= n; ++j) {
                for (int p = 0; p <= k; ++p) {
                    wayNums[i][j][p] = addMod(
                            addMod(multiplyMod(2 * j + 1, getWayNum(wayNums, i - 1, j, p - 2 * j)),
                                    multiplyMod((j + 1) * (j + 1), getWayNum(wayNums, i - 1, j + 1, p - 2 * j))),
                            getWayNum(wayNums, i - 1, j - 1, p - 2 * j));
                }
            }
        }

        return wayNums[n][0][k];
    }

    static int getWayNum(int[][][] wayNums, int seenNum, int unpairNum, int oddness) {
        int n = wayNums.length - 1;

        return (unpairNum == -1 || unpairNum == n + 1 || oddness < 0) ? 0 : wayNums[seenNum][unpairNum][oddness];
    }

    static int addMod(int x, int y) {
        return (x + y) % MODULUS;
    }

    static int multiplyMod(int x, int y) {
        return (int) ((long) x * y % MODULUS);
    }
}