#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 3000;
const int MOD = 1e9 + 7;
ll dp[N + 10][N + 10];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n, m;
cin >> n >> m;
for(int i = 0; i <= n; i++) dp[i][0] = 1;
for(int j = 0; j <= m; j++) dp[0][j] = 1;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
dp[i][j] += dp[i - 1][j];
dp[i][j] += 4 * j * dp[i - 1][j - 1] % MOD;
if(j > 1) dp[i][j] += j * (j - 1) / 2 * dp[i - 1][j - 2] % MOD;
if(i > 1) dp[i][j] += (i - 1) * j * dp[i - 2][j - 1] % MOD;
dp[i][j] %= MOD;
}
}
cout << (dp[n][m] - 1 + MOD) % MOD;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
1108 KB |
Output is correct |
5 |
Correct |
1 ms |
720 KB |
Output is correct |
6 |
Correct |
1 ms |
1364 KB |
Output is correct |
7 |
Correct |
1 ms |
852 KB |
Output is correct |
8 |
Correct |
1 ms |
1364 KB |
Output is correct |
9 |
Correct |
1 ms |
716 KB |
Output is correct |
10 |
Correct |
1 ms |
1748 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
2124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
1108 KB |
Output is correct |
5 |
Correct |
1 ms |
720 KB |
Output is correct |
6 |
Correct |
1 ms |
1364 KB |
Output is correct |
7 |
Correct |
1 ms |
852 KB |
Output is correct |
8 |
Correct |
1 ms |
1364 KB |
Output is correct |
9 |
Correct |
1 ms |
716 KB |
Output is correct |
10 |
Correct |
1 ms |
1748 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
2124 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
4 ms |
9612 KB |
Output is correct |
15 |
Correct |
63 ms |
55136 KB |
Output is correct |
16 |
Correct |
4 ms |
4052 KB |
Output is correct |
17 |
Correct |
14 ms |
12876 KB |
Output is correct |
18 |
Correct |
18 ms |
17100 KB |
Output is correct |
19 |
Correct |
72 ms |
62924 KB |
Output is correct |
20 |
Correct |
59 ms |
50852 KB |
Output is correct |
21 |
Correct |
40 ms |
33812 KB |
Output is correct |
22 |
Correct |
39 ms |
35424 KB |
Output is correct |
23 |
Correct |
25 ms |
27092 KB |
Output is correct |
24 |
Correct |
94 ms |
71068 KB |
Output is correct |
25 |
Correct |
73 ms |
61332 KB |
Output is correct |
26 |
Correct |
83 ms |
66740 KB |
Output is correct |
27 |
Correct |
89 ms |
69132 KB |
Output is correct |