Submission #736145

#TimeUsernameProblemLanguageResultExecution timeMemory
736145marvinthangZapina (COCI20_zapina)C++17
110 / 110
130 ms1744 KiB
/******************************
*    author : @marvinthang    *
*    date : 14 / 11 / 2021    *
******************************/
 
#include <bits/stdc++.h>
 
using namespace std;
 
#define  superspeed  ios_base::sync_with_stdio(false);\
                     cin.tie(NULL);\
                     //cout.tie(NULL);
#define  file(name)  freopen(name".inp", "r", stdin);\
                     freopen(name".out", "w", stdout);
 
const       int MOD = 1e9 + 7; // 998244353;
const     double PI = 3.1415926535897932384626433832795; // acos((db)-1); atan(-1.0);
const      int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
const  long long oo = 1e18;
const       int MAX = 355;
 
void add(int &a, int b) {
    a += b;
    if (a >= MOD) a -= MOD;
}
 
int N, F[MAX][MAX][2], comb[MAX][MAX];
 
void prepare() {
    comb[0][0] = 1;
    for (int i = 1; i <= N; ++i) {
        comb[0][i] = 1;
        for (int j = 1; j <= i; ++j) {
            comb[j][i] = comb[j][i - 1];
            add(comb[j][i], comb[j - 1][i - 1]);
        }
    }
}
 
int main() {
    superspeed;
    cin >> N;
    prepare();
    F[0][0][0] = 1;
    for (int i = 1; i <= N; ++i) {
        for (int j = 0; j <= N; ++j) {
            if (j >= i) add(F[i][j][1], 1LL * comb[i][j] * F[i - 1][j - i][0] % MOD);
            for (int k = 0; k <= j; ++k) {
                if (k != i) add(F[i][j][0], 1LL * comb[k][j] * F[i - 1][j - k][0] % MOD);
                add(F[i][j][1], 1LL * comb[k][j] * F[i - 1][j - k][1] % MOD);
            }
        }
    }
    cout << F[N][N][1] << '\n';
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...