Submission #229236

#TimeUsernameProblemLanguageResultExecution timeMemory
229236VEGAnnZapina (COCI20_zapina)C++14
110 / 110
182 ms2248 KiB
#include <bits/stdc++.h> #define sz(x) ((int)x.size()) #define pii pair<int,int> #define ft first #define sd second #define all(x) x.begin(),x.end() #define PB push_back #define MP make_pair using namespace std; typedef long long ll; const int md = int(1e9) + 7; const int N = 410; const int PW = 20; int f[N][N][2], c[N][N], n; int sum(int x, int y){ x += y; if (x >= md) x -= md; return x; } int mult(int x, int y) { return (1ll * x * y) % md;} int main(){ ios_base::sync_with_stdio(0); cin.tie(0); // freopen("in.txt","r",stdin); cin >> n; c[0][0] = 1; for (int i = 1; i <= n; i++){ c[i][0] = c[i][i] = 1; for (int j = 1; j < i; j++) c[i][j] = sum(c[i - 1][j], c[i - 1][j - 1]); } f[0][n][0] = 1; for (int i = 0; i < n; i++) for (int ost = 0; ost <= n; ost++) for (int tp = 0; tp < 2; tp++){ if (f[i][ost][tp] == 0) continue; for (int nw = 0; nw <= ost; nw++){ int ni = i + 1, nost = ost - nw, ntp = tp; if (nw == ni) ntp = 1; f[ni][nost][ntp] = sum(f[ni][nost][ntp], mult(f[i][ost][tp], c[ost][nw])); } } cout << f[n][0][1]; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...