This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define left 2*i+1
#define righ 2*i+2
#define mid (l+r)/2
using namespace std;
const ll mod=1e9+7;
ll n,dp[400][400][2],ch[400][400];
ll solve(ll st,ll pr,ll ok){
    if(st==n){
        if(pr==n)return ok;
        return 0;
    }
    ll &ans=dp[st][pr][ok];
    if(ans+1)return ans;
    ans=0;
    for(ll i=0;i+pr<=n;i++){
        if(st+1==i){
            ans=(ans+solve(st+1,pr+i,1)*ch[n-pr][i]%mod)%mod;
        }
        else
        ans=(ans+solve(st+1,pr+i,ok)*ch[n-pr][i]%mod)%mod;
    }
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;
    memset(dp,-1,sizeof dp);
    for(ll i=0;i+25<400;i++){
        ch[i][0]=1;
        for(ll j=1;j<=i;j++){
            ch[i][j]=(ch[i-1][j]+ch[i-1][j-1])%mod;
        }
    }
    cout<<solve(0,0,0)<<endl;
    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... |