#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
const int N = 3e3 + 5;
const int mod = 1e9 + 7;
ll dp1[N][N], dp2[N];
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int h, w;
cin >> h >> w;
dp1[0][w] = 1;
for (int i = 0; i < h; i++) {
for (int j = w; j >= 0; j--) {
if (j >= 2) {
dp1[i + 1][j - 2] += ((j * (j - 1) / 2) % mod) * dp1[i][j];
dp1[i + 1][j - 2] %= mod;
}
if (j >= 1) {
dp1[i + 1][j - 1] += j * dp2[j] + 4 * j * dp1[i][j];
dp1[i + 1][j - 1] %= mod;
}
dp1[i + 1][j] += dp1[i][j];
dp1[i + 1][j] %= mod;
dp2[j] += (i + 1) * dp1[i][j] - i * dp1[max(i - 1, 0)][j];
dp2[j] %= mod;
}
}
ll ans = 0;
for (int i = 0; i < w; i++) {
ans += dp1[h][i];
ans %= mod;
}
cout << ans << "\n";
// for (int i = 0; i <= h; i++) {
// for (int j = w; j >= 0; j--) cout << dp1[i][j] << " ";
// cout << "\n";
// }
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
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 |
1 ms |
1748 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
2132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
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 |
1 ms |
1748 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
2132 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
5 ms |
9684 KB |
Output is correct |
15 |
Correct |
72 ms |
55196 KB |
Output is correct |
16 |
Correct |
5 ms |
4052 KB |
Output is correct |
17 |
Correct |
17 ms |
12836 KB |
Output is correct |
18 |
Correct |
21 ms |
17056 KB |
Output is correct |
19 |
Correct |
85 ms |
62924 KB |
Output is correct |
20 |
Correct |
70 ms |
50820 KB |
Output is correct |
21 |
Correct |
45 ms |
33724 KB |
Output is correct |
22 |
Correct |
45 ms |
35452 KB |
Output is correct |
23 |
Correct |
33 ms |
27128 KB |
Output is correct |
24 |
Correct |
111 ms |
70868 KB |
Output is correct |
25 |
Correct |
87 ms |
61228 KB |
Output is correct |
26 |
Correct |
96 ms |
66596 KB |
Output is correct |
27 |
Correct |
103 ms |
68932 KB |
Output is correct |