#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MX = 3005, mod = 1e9 + 7, inv = 5e8 + 4;
int H, W;
ll dp[MX][MX];
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
cin >> H >> W;
dp[0][W] = 1;
for(int i = 0; i < H; i++) {
for(int a = 0; a <= W; a++) {
dp[i + 1][a] += dp[i][a];
dp[i + 1][a] %= mod;
if(a - 1 >= 0) {
dp[i + 1][a - 1] += 1LL * dp[i][a] * a * 4 % mod;
dp[i + 1][a - 1] %= mod;
}
if(a - 2 >= 0) {
dp[i + 1][a - 2] += 1LL * dp[i][a] * a % mod * (a - 1) % mod * inv % mod;
dp[i + 1][a - 2] %= mod;
}
if(i + 2 <= H && a - 1 >= 0) {
dp[i + 2][a - 1] += 1LL * dp[i][a] * (H - i - 1) % mod * a % mod;
dp[i + 2][a - 1] %= mod;
}
}
}
ll ans = 0;
for(int a = 0; a < W; a++) {
ans += dp[H][a];
ans %= mod;
}
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
1108 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
1364 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
1364 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
2 ms |
1748 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
3 ms |
2216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
1108 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
1364 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
1364 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
2 ms |
1748 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
3 ms |
2216 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
5 ms |
9556 KB |
Output is correct |
15 |
Correct |
113 ms |
55176 KB |
Output is correct |
16 |
Correct |
8 ms |
4044 KB |
Output is correct |
17 |
Correct |
26 ms |
12860 KB |
Output is correct |
18 |
Correct |
32 ms |
16980 KB |
Output is correct |
19 |
Correct |
128 ms |
62912 KB |
Output is correct |
20 |
Correct |
105 ms |
50828 KB |
Output is correct |
21 |
Correct |
75 ms |
33824 KB |
Output is correct |
22 |
Correct |
70 ms |
35468 KB |
Output is correct |
23 |
Correct |
43 ms |
26992 KB |
Output is correct |
24 |
Correct |
170 ms |
70856 KB |
Output is correct |
25 |
Correct |
130 ms |
61204 KB |
Output is correct |
26 |
Correct |
162 ms |
66572 KB |
Output is correct |
27 |
Correct |
163 ms |
69008 KB |
Output is correct |