#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 time |
Memory |
Grader output |
1 |
Correct |
30 ms |
35704 KB |
Output is correct |
2 |
Correct |
30 ms |
35712 KB |
Output is correct |
3 |
Correct |
30 ms |
35704 KB |
Output is correct |
4 |
Correct |
28 ms |
35716 KB |
Output is correct |
5 |
Correct |
30 ms |
35704 KB |
Output is correct |
6 |
Correct |
29 ms |
35704 KB |
Output is correct |
7 |
Correct |
29 ms |
35704 KB |
Output is correct |
8 |
Correct |
31 ms |
35676 KB |
Output is correct |
9 |
Correct |
29 ms |
35624 KB |
Output is correct |
10 |
Correct |
30 ms |
35704 KB |
Output is correct |
11 |
Correct |
31 ms |
35708 KB |
Output is correct |
12 |
Correct |
32 ms |
35676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
35704 KB |
Output is correct |
2 |
Correct |
30 ms |
35712 KB |
Output is correct |
3 |
Correct |
30 ms |
35704 KB |
Output is correct |
4 |
Correct |
28 ms |
35716 KB |
Output is correct |
5 |
Correct |
30 ms |
35704 KB |
Output is correct |
6 |
Correct |
29 ms |
35704 KB |
Output is correct |
7 |
Correct |
29 ms |
35704 KB |
Output is correct |
8 |
Correct |
31 ms |
35676 KB |
Output is correct |
9 |
Correct |
29 ms |
35624 KB |
Output is correct |
10 |
Correct |
30 ms |
35704 KB |
Output is correct |
11 |
Correct |
31 ms |
35708 KB |
Output is correct |
12 |
Correct |
32 ms |
35676 KB |
Output is correct |
13 |
Correct |
49 ms |
35704 KB |
Output is correct |
14 |
Correct |
29 ms |
35832 KB |
Output is correct |
15 |
Correct |
284 ms |
35832 KB |
Output is correct |
16 |
Correct |
31 ms |
35704 KB |
Output is correct |
17 |
Correct |
44 ms |
35708 KB |
Output is correct |
18 |
Correct |
77 ms |
35704 KB |
Output is correct |
19 |
Correct |
347 ms |
35932 KB |
Output is correct |
20 |
Correct |
237 ms |
35920 KB |
Output is correct |
21 |
Correct |
125 ms |
35832 KB |
Output is correct |
22 |
Correct |
146 ms |
35872 KB |
Output is correct |
23 |
Correct |
126 ms |
35960 KB |
Output is correct |
24 |
Correct |
383 ms |
35924 KB |
Output is correct |
25 |
Correct |
278 ms |
35992 KB |
Output is correct |
26 |
Correct |
326 ms |
35832 KB |
Output is correct |
27 |
Correct |
360 ms |
35960 KB |
Output is correct |