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>
using namespace std;
#define int long long
const int MAX = 350 + 5;
const int MOD = 1e9 + 7;
int add(int a, const int &b) {
    a += b;
    while (a >= MOD) a -= MOD;
    while (a < 0) a += MOD;
    return a;
}
int f[MAX][MAX][2], c[MAX][MAX];
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("chiakeo.inp", "r", stdin); freopen("chiakeo.out", "w", stdout);
    int n;
    cin >> n;
    c[0][0] = 1;
    for (int i = 1; i <= n; i++) {
            for (int j = 0; j <= i; j++) {
                c[i][j] = c[i - 1][j];
                if (j) c[i][j] = add(c[i][j], c[i - 1][j - 1]);
            }
    }
    f[0][0][0]  = 1;
    for (int i = 1; i <= n; i++) {
            for (int j = 0; j <= n; j++) {
                    for (int z = 0; z <= j; z++) {
                        if (z == i) {
                                f[i][j][1] = add(f[i][j][1], add(f[i - 1][j - z][1], f[i - 1][j - z][0]) * c[j][z] % MOD);
                        }
                        else {
                                f[i][j][0] = add(f[i][j][0], f[i - 1][j - z][0] * c[j][z] % MOD);
                                f[i][j][1] = add(f[i][j][1], f[i - 1][j - z][1] * c[j][z] % MOD);
                        }
                    }
            }
    }
    cout << f[n][n][1];
    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... |