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++14 (GCC 5.4.1) (judge verdict: Accepted)

#include<bits/stdc++.h>
using namespace std;
const int maxn=55;
typedef long long ll;
const int mod=1e9+7;
ll dp[maxn][maxn][maxn*maxn];
int main()
{
	int n,k;cin>>n>>k;
	dp[0][0][0]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=n;j++)
		{
			for(int x=0;x<=n*n;x++)
			{
				if(x-2*j>=0)
				dp[i][j][x]+=(2*j+1)*dp[i-1][j][x-2*j];
				//包括了在这个地方 i和i配对了，然后前面没有
				//配对的j个兔子和j个乌龟与后面的配对，那么
				//在这个地方的贡献就是2*j
				//这个地方兔子i和乌龟i没有配对，那么兔子i和
				//前面某个乌龟z配对了，这样没配对的还是有j个兔子
				//j个乌龟，贡献还是2*j 
				if(j+1<=n && x-2*j>=0)
				dp[i][j][x]+=(j+1)*(j+1)*dp[i-1][j+1][x-2*j];
				//在这之前 有j+1个没有配对，然后在这个地方配对两个
				//兔子i可以在j+1个乌龟里面选，乌龟i可以在j+1个兔子里面选
				//选完之后，还有j个没有配对，那么他们贡献加上2*j
				 if(j-1>=0 && x-2*j>=0 )
				 dp[i][j][x]+=dp[i-1][j-1][x-2*j];
				 //都不配对 以前有j-1个 现在有j个 
				 dp[i][j][x]%=mod;
			}
		}
	}
	cout<<dp[n][0][k]<<endl;
 }