#include <bits/stdc++.h>
#define ar array
//#define int long long
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const ll inf = 1e18;
const int maxn = 1e5 + 5;
int n, m;
ll dp[305][305][305];
ll coef(ll x) {
    x = x * (x - 1) / 2;
    return x % mod;
}
ll f(int r, int c, int k) {
    if(r == n + 1) return 1;
    if(dp[r][c][k] != -1) return dp[r][c][k];
    //nisto
    ll ans = f(r+1, c, k);
    //EW
    if(c >= 2) ans = (ans + f(r+1, c-2, k) * coef(c)) % mod;
    
    //N na S
    if(k) ans = (ans + f(r+1, c, k-1) * k) % mod;
    //S sto ne e na N
    if(c >= 1) ans = (ans + f(r+1, c-1, k) * c) % mod;
    //N
    if(c >= 1) ans = (ans + f(r+1, c-1, k+1) * c) % mod;
    if(c >= 1) ans = (ans + f(r+1, c-1, k) * 2ll * c) % mod;
    return dp[r][c][k] = ans;
}
signed main() {
    memset(dp, -1, sizeof(dp));
    cin >> n >> m;
    cout << (f(1, m, 0) - 1 + mod) % mod << '\n';
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |