#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
using i32 = int;
using u32 = unsigned;
using i16 = short;
using u16 = unsigned short;
using ld = long double;
using ii = pair<int, int>;
const int mod = 1e9 + 7, N = 3e3 + 1;
i64 dp[N][N];
int mod_sum(int x) {
return x < mod ? x : x - mod;
}
void solve() {
int h, w, ans = 0;
cin >> h >> w;
dp[h][w] = 1;
for(int x = h; x >= 0; --x) {
for(int y = w; y >= 0; --y) {
if(x > 0 && y >= 2) {
i64 ways = y * (y - 1LL) / 2 % mod * dp[x][y] % mod;
dp[x - 1][y - 2] = (dp[x - 1][y - 2] + ways) % mod;
ans = mod_sum(ans + ways);
}
if(x >= 2 && y > 0) {
i64 ways = dp[x][y] * (x - 1) % mod * y % mod;
dp[x - 2][y - 1] = (dp[x - 2][y - 1] + ways) % mod;
ans = mod_sum(ans + ways);
}
if(x > 0 && y > 0) {
i64 ways = 4LL * y * dp[x][y] % mod;
dp[x - 1][y - 1] = (dp[x - 1][y - 1] + ways) % mod;
ans = mod_sum(ans + ways);
}
if(x > 0) dp[x - 1][y] = mod_sum(dp[x - 1][y] + dp[x][y]);
}
}
cout << ans << '\n';
}
int main() {
ios_base :: sync_with_stdio(false);
cin.tie(0);
int t = 1;
//cin >> t;
while(t--) solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
6 |
Correct |
1 ms |
1352 KB |
Output is correct |
7 |
Correct |
1 ms |
716 KB |
Output is correct |
8 |
Correct |
1 ms |
1356 KB |
Output is correct |
9 |
Correct |
1 ms |
716 KB |
Output is correct |
10 |
Correct |
2 ms |
1740 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
4 ms |
2236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
6 |
Correct |
1 ms |
1352 KB |
Output is correct |
7 |
Correct |
1 ms |
716 KB |
Output is correct |
8 |
Correct |
1 ms |
1356 KB |
Output is correct |
9 |
Correct |
1 ms |
716 KB |
Output is correct |
10 |
Correct |
2 ms |
1740 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
4 ms |
2236 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
6 ms |
9664 KB |
Output is correct |
15 |
Correct |
147 ms |
55144 KB |
Output is correct |
16 |
Correct |
10 ms |
4044 KB |
Output is correct |
17 |
Correct |
43 ms |
12736 KB |
Output is correct |
18 |
Correct |
45 ms |
17004 KB |
Output is correct |
19 |
Correct |
184 ms |
62956 KB |
Output is correct |
20 |
Correct |
145 ms |
50808 KB |
Output is correct |
21 |
Correct |
91 ms |
33708 KB |
Output is correct |
22 |
Correct |
92 ms |
35424 KB |
Output is correct |
23 |
Correct |
55 ms |
27048 KB |
Output is correct |
24 |
Correct |
227 ms |
70660 KB |
Output is correct |
25 |
Correct |
174 ms |
61152 KB |
Output is correct |
26 |
Correct |
199 ms |
66516 KB |
Output is correct |
27 |
Correct |
233 ms |
68824 KB |
Output is correct |