Submission #442918

#TimeUsernameProblemLanguageResultExecution timeMemory
442918colossal_pepeZapina (COCI20_zapina)C++17
110 / 110
157 ms2272 KiB
#include <iostream> #include <cstring> using namespace std; typedef long long ll; const ll MOD = 1000000007; ll n, C[355][355], dp[355][355]; void fillC() { C[0][0] = 1; for (int i = 1; i < 355; i++) { C[i][0] = C[i][i] = 1; for (int j = 1; j < 355; j++) { C[i][j] = C[i - 1][j - 1] + C[i - 1][j]; C[i][j] %= MOD; } } } void setup() { memset(dp, -1, sizeof(dp)); for (int i = n + 1; i < 355; i++) { dp[i][0] = 1; for (int j = 1; j < 355; j++) { dp[i][j] = 0; } } } ll modMinus(ll a, ll b) { ll ans = a%MOD - b%MOD; if (ans < 0) ans += MOD; return ans; } ll ways(ll x) { ll ans = 1; for (int i = 0; i < x; i++) { ans *= x; ans %= MOD; } return ans; } ll badWays(ll p, ll t) { if (dp[p][t] != -1) return dp[p][t]; dp[p][t] = 0; for (int i = 0; i <= t; i++) { if (i == p) continue; dp[p][t] += C[t][i] * badWays(p + 1, t - i); dp[p][t] %= MOD; } return dp[p][t]; } int main() { fillC(); cin >> n; setup(); cout << modMinus(ways(n), badWays(1, n)) << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...