#include<bits/stdc++.h>
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;
int Q[3001][3001];
int dp(int x, int y){
if(x < 0 || y < 0) return 0;
if(x == 0 || y == 0) return Q[x][y] = 1;
if(Q[x][y] != -1) return Q[x][y];
int ret = 0;
ret += dp(x - 1, y - 2) * ((y - 1) * y / 2) % modulo;
ret += dp(x - 2, y - 1) * y * (x - 1) % modulo;
ret %= modulo;
ret += dp(x - 1, y - 1) * 4ll * y % modulo;
ret += dp(x - 1, y) % modulo;
return Q[x][y] = ret % modulo;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
for(int i = 0; i <= n; i++){
for(int j = 0; j <= m; j++){
Q[i][j] = -1;
}
}
cout << (dp(n, m) - 1 + modulo) % modulo << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
508 KB |
Output is correct |
4 |
Correct |
6 ms |
1144 KB |
Output is correct |
5 |
Correct |
5 ms |
760 KB |
Output is correct |
6 |
Correct |
6 ms |
1400 KB |
Output is correct |
7 |
Correct |
5 ms |
888 KB |
Output is correct |
8 |
Correct |
5 ms |
1528 KB |
Output is correct |
9 |
Correct |
5 ms |
888 KB |
Output is correct |
10 |
Correct |
6 ms |
1784 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
9 ms |
2168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
508 KB |
Output is correct |
4 |
Correct |
6 ms |
1144 KB |
Output is correct |
5 |
Correct |
5 ms |
760 KB |
Output is correct |
6 |
Correct |
6 ms |
1400 KB |
Output is correct |
7 |
Correct |
5 ms |
888 KB |
Output is correct |
8 |
Correct |
5 ms |
1528 KB |
Output is correct |
9 |
Correct |
5 ms |
888 KB |
Output is correct |
10 |
Correct |
6 ms |
1784 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
9 ms |
2168 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
11 ms |
9848 KB |
Output is correct |
15 |
Correct |
276 ms |
55544 KB |
Output is correct |
16 |
Correct |
8 ms |
4088 KB |
Output is correct |
17 |
Correct |
26 ms |
12920 KB |
Output is correct |
18 |
Correct |
55 ms |
17272 KB |
Output is correct |
19 |
Correct |
315 ms |
63352 KB |
Output is correct |
20 |
Correct |
231 ms |
51064 KB |
Output is correct |
21 |
Correct |
120 ms |
33912 KB |
Output is correct |
22 |
Correct |
169 ms |
35704 KB |
Output is correct |
23 |
Correct |
113 ms |
27384 KB |
Output is correct |
24 |
Correct |
384 ms |
71160 KB |
Output is correct |
25 |
Correct |
288 ms |
61436 KB |
Output is correct |
26 |
Correct |
317 ms |
66808 KB |
Output is correct |
27 |
Correct |
379 ms |
69112 KB |
Output is correct |