#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair <int , int>
#define int long long
using namespace std;
const int INF = 1e9 + 7;
const int maxn = 5e5 + 7;
const int mod = 1e9 + 7;
int n , dp[357][357][357] , C[357][357];
void build_Cnk()
{
    C[0][0] = 1;
    for(int i = 1; i <= 350; i++)
    {
        C[i][0] = 1;
        C[i][i] = 1;
        for(int j = 1; j < i; j++)
        {
            C[i][j] = (C[i-1][j] + C[i-1][j-1])%mod;
        }
    }
}
void solve()
{
    cin >> n;
    dp[0][0][0] = 1;
    for(int i = 1; i <= n; i++)
    {
        for(int x = 0; x <= n; x++)
        {
            for(int j = 0; (x + j) <= n; j++)
            {
                dp[i][x+j][1] = (dp[i][x+j][1] + dp[i-1][j][1]*C[n - j][x])%mod;
                if(x == i)
                {
                    dp[i][x+j][1] = (dp[i][x+j][1] + dp[i-1][j][0]*C[n-j][x])%mod;
                }
            }
            if(x == i) continue;
            for(int j = 0; (x + j) <= n; j++)
            {
                dp[i][x+j][0] = (dp[i][x+j][0] + dp[i-1][j][0]*C[n-j][x])%mod;
            }
        }
    }
    cout << dp[n][n][1] << '\n';
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    build_Cnk();
    solve();
    return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |