Submission #44654

#TimeUsernameProblemLanguageResultExecution timeMemory
44654PowerOfNinjaGoTents (JOI18_tents)C++17
100 / 100
511 ms36224 KiB
#include <bits/stdc++.h> using namespace std; const int md = 1e9+7; const int maxn = 3e3+5; int dp[maxn][maxn]; void add(int &a, int b) { a += b; if(a>= md) a-= md; } int mul(int a, int b) { return (1LL*a*b)%md; } int solve(int n, int m) { if(n == 0 || m == 0) return 1; if(dp[n][m] != -1) return dp[n][m]; int &res = dp[n][m]; res = 0; add(res, mul(4*m, solve(n-1, m-1))); if(n>= 2) add(res, mul(m*(n-1), solve(n-2, m-1))); if(m>= 2) add(res, mul(m*(m-1)/2, solve(n-1, m-2))); add(res, solve(n-1, m)); return res; } int main() { int n, m; cin >> n >> m; memset(dp, -1, sizeof dp); cout << solve(n, m)-1 << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...