Submission #1032103

#TimeUsernameProblemLanguageResultExecution timeMemory
1032103juicyTents (JOI18_tents)C++17
100 / 100
240 ms35932 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif const int MD = 1e9 + 7; int F[3001][3001]; int add(int x, int y) { if ((x += y) >= MD) { x -= MD; } if (x < 0) { x += MD; } return x; } int C2(int N) { return N * (N - 1) / 2; } int dp(int i, int j) { if (i < 0 || j < 0) { return 0; } if (i == 0) { return 1; } if (~F[i][j]) { return F[i][j]; } int &res = F[i][j]; res = 0; res = add(res, dp(i - 1, j)); res = add(res, (long long) dp(i - 1, j - 2) * C2(j) % MD); res = add(res, (long long) dp(i - 1, j - 1) * 4 % MD * j % MD); res = add(res, (long long) dp(i - 2, j - 1) * (i - 1) % MD * j % MD); return res; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, M; cin >> N >> M; memset(F, -1, sizeof(F)); cout << add(dp(N, M), -1); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...