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 C# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;

class F
{
	static void Main()
	{
		var M = 1000000007;
		var h = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		int n = h[0], k = h[1], n2 = n * n;

		var dp = new long[n + 1, n + 1, n2 + 1];
		dp[0, 0, 0] = 1;
		for (int i = 0; i < n; i++)
			for (int j = 0; j <= n; j++)
				for (int t, x = 0; x <= n2; x++)
				{
					if (dp[i, j, x] == 0) continue;
					if (j > 0 && (t = x + 2 * j - 2) <= n2)
					{
						dp[i + 1, j - 1, t] += j * j * dp[i, j, x];
						dp[i + 1, j - 1, t] %= M;
					}
					if ((t = x + 2 * j) <= n2)
					{
						dp[i + 1, j, t] += (2 * j + 1) * dp[i, j, x];
						dp[i + 1, j, t] %= M;
					}
					if ((t = x + 2 * j + 2) <= n2)
					{
						dp[i + 1, j + 1, t] += dp[i, j, x];
						dp[i + 1, j + 1, t] %= M;
					}
				}
		Console.WriteLine(dp[n, 0, k]);
	}
}