#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 3003, M = N;
int n, m, dp[N][M];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= m; ++j) {
if(i == 1 && j == 1) {
dp[i][j] = 5;
} else if(i == 1) {
dp[i][j] = 1ll + j * 4 + j * (j - 1) / 2;
} else if(j == 1) {
dp[i][j] = 1ll + i * 4 + i * (i - 1) / 2;
} else if(j == 2 && i == 2) {
dp[i][j] = 53;
} else if(j == 2) {
dp[i][j] = (1ll + dp[i - 1][j] + 8ll * dp[i - 1][j - 1] + 2ll * (i - 1) * dp[i - 2][j - 1]) % mod;
} else if(i == 2) {
dp[i][j] = (1ll + dp[i][j - 1] + 8ll * dp[i - 1][j - 1] + 2ll * (j - 1) * dp[i - 1][j - 2]) % mod;
} else {
dp[i][j] = (1ll * dp[i - 1][j] + 4ll * j * dp[i - 1][j - 1] + 1ll * j * (i - 1) * dp[i - 2][j - 1] + 1ll * j * (j - 1) / 2 * dp[i - 1][j - 2]) % mod;
}
}
}
cout << (dp[n][m] + mod - 1) % mod;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
2 ms |
1132 KB |
Output is correct |
5 |
Correct |
1 ms |
620 KB |
Output is correct |
6 |
Correct |
1 ms |
1388 KB |
Output is correct |
7 |
Correct |
1 ms |
872 KB |
Output is correct |
8 |
Correct |
1 ms |
1388 KB |
Output is correct |
9 |
Correct |
1 ms |
876 KB |
Output is correct |
10 |
Correct |
2 ms |
1644 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
1900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
2 ms |
1132 KB |
Output is correct |
5 |
Correct |
1 ms |
620 KB |
Output is correct |
6 |
Correct |
1 ms |
1388 KB |
Output is correct |
7 |
Correct |
1 ms |
872 KB |
Output is correct |
8 |
Correct |
1 ms |
1388 KB |
Output is correct |
9 |
Correct |
1 ms |
876 KB |
Output is correct |
10 |
Correct |
2 ms |
1644 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
1900 KB |
Output is correct |
13 |
Correct |
1 ms |
512 KB |
Output is correct |
14 |
Correct |
5 ms |
9580 KB |
Output is correct |
15 |
Correct |
54 ms |
32868 KB |
Output is correct |
16 |
Correct |
4 ms |
2668 KB |
Output is correct |
17 |
Correct |
13 ms |
8044 KB |
Output is correct |
18 |
Correct |
16 ms |
10988 KB |
Output is correct |
19 |
Correct |
77 ms |
34532 KB |
Output is correct |
20 |
Correct |
50 ms |
29156 KB |
Output is correct |
21 |
Correct |
33 ms |
19820 KB |
Output is correct |
22 |
Correct |
34 ms |
22252 KB |
Output is correct |
23 |
Correct |
23 ms |
19692 KB |
Output is correct |
24 |
Correct |
87 ms |
35556 KB |
Output is correct |
25 |
Correct |
60 ms |
30820 KB |
Output is correct |
26 |
Correct |
75 ms |
33636 KB |
Output is correct |
27 |
Correct |
77 ms |
34784 KB |
Output is correct |