Submission #914337

#TimeUsernameProblemLanguageResultExecution timeMemory
914337borisAngelovTents (JOI18_tents)C++17
100 / 100
191 ms79348 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 3005; const int mod = 1e9 + 7; int n, m; bool bl[maxn][maxn]; long long dp[maxn][maxn]; long long f(int rows, int cols) { if (rows < 0 || cols < 0) { return 0; } if (rows == 0 || cols == 0) { return 1; } if (bl[rows][cols] == true) { return dp[rows][cols]; } bl[rows][cols] = true; long long ans = 0; ans += f(rows - 1, cols); ans %= mod; ans += (4LL * cols) * f(rows - 1, cols - 1); ans %= mod; ans += ((1LL * cols) * (1LL * cols - 1LL) / 2LL) * f(rows - 1, cols - 2); ans %= mod; ans += (1LL * cols) * (1LL * (rows - 1)) * f(rows - 2, cols - 1); ans %= mod; return dp[rows][cols] = ans; } void fastIO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { fastIO(); cin >> n >> m; cout << f(n, m) - 1 << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...