#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long dp[3008][3008];
long long C2(int x) {return (1LL * x * (x - 1) / 2) % mod;}
signed main() {
int n, m; cin >> n >> m;
for (int i = 0; i <= m; ++i) dp[0][i] = 1;
for (int i = 0; i <= n; ++i) dp[i][0] = 1;
for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j)
dp[i][j] = (dp[i][j - 1] + dp[i - 1][j - 1] * i * 4 + dp[i - 2][j - 1] * C2(i) + dp[i - 1][j - 2] * i * (j - 1)) % mod;
cout << (dp[n][m] + mod -1 ) % mod;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
2 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
2 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
4 ms |
24932 KB |
Output is correct |
15 |
Correct |
42 ms |
58716 KB |
Output is correct |
16 |
Correct |
2 ms |
6492 KB |
Output is correct |
17 |
Correct |
7 ms |
16988 KB |
Output is correct |
18 |
Correct |
11 ms |
25684 KB |
Output is correct |
19 |
Correct |
48 ms |
64852 KB |
Output is correct |
20 |
Correct |
38 ms |
54100 KB |
Output is correct |
21 |
Correct |
23 ms |
37468 KB |
Output is correct |
22 |
Correct |
26 ms |
44052 KB |
Output is correct |
23 |
Correct |
18 ms |
42584 KB |
Output is correct |
24 |
Correct |
63 ms |
70884 KB |
Output is correct |
25 |
Correct |
44 ms |
61268 KB |
Output is correct |
26 |
Correct |
51 ms |
66564 KB |
Output is correct |
27 |
Correct |
57 ms |
69192 KB |
Output is correct |