Submission #447160

#TimeUsernameProblemLanguageResultExecution timeMemory
447160bi11a1Zapina (COCI20_zapina)C++17
110 / 110
508 ms3308 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; const ll mod = 1e9+7; const ll MX = 351; ll n; ll dp[MX][MX][2], nr_dp[MX][MX]; ll nCr(ll N, ll R) { if (R == 1) return N; if (N == R || R == 0) return 1; ll &res = nr_dp[N][R]; if (res != -1) return res; res = nCr(N-1, R) + nCr(N-1, R-1); res %= mod; return res; } ll Calc(ll pos, ll rem, bool happy) { if (pos > n) { return (happy && rem == 0); } ll &res = dp[pos][rem][happy]; if (res != -1) return res; res = 0; for (ll i = 0; i <= rem; ++i) { res += nCr(rem, i) * Calc(pos+1, rem-i, happy | (pos==i)); res %= mod; } return res; } int main() { memset(dp, -1, sizeof dp); memset(nr_dp, -1, sizeof nr_dp); cin >> n; cout << Calc(1, n, 0) << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...