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 Rust (1.15.1) (judge verdict: Accepted)

#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, k) = (v[0], v[1]);
    let mut dp = vec![vec![vec![0; 1500 + 1]; 55]; 55];
    dp[0][0][0] = 1;
    let big_int = 1000_000_000 + 7;
    for i in 0..n {
        for j in 0..i + 1 {
            for ki in 0..k / 2 + 1 {
                // a) connect both
                dp[i + 1][j][ki + j] += dp[i][j][ki];
                dp[i + 1][j][ki + j] %= big_int;
                // b) both wait
                dp[i + 1][j + 1][ki + j + 1] += dp[i][j][ki];
                dp[i + 1][j + 1][ki + j + 1] %= big_int;
                // c)
                dp[i + 1][j][ki + j] += dp[i][j][ki] * 2 * j;
                dp[i + 1][j][ki + j] %= big_int;
                // d)
                if j > 0 {
                    let x = (j * j) % big_int;
                    dp[i + 1][j - 1][ki + j - 1] += dp[i][j][ki] * x;
                    dp[i + 1][j - 1][ki + j - 1] %= big_int;
                }
            }
        }
    }
    if k % 2 == 1 {
        println!("{}", 0);
    } else {
        println!("{}", dp[n][0][k / 2]);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}