#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int mem[3003][3003];
long long dp(int H, int W) {
if(H < 0) return 0;
if(W < 0) return 0;
if(H == 0 || W == 0) return 1;
if(mem[H][W] != -1) return mem[H][W];
long long ans = 0;
ans += dp(H - 1, W);
ans += dp(H - 1, W - 2) * ((W * (W - 1)) / 2);
ans += 4LL * dp(H - 1, W - 1) * W;
ans += dp(H - 2, W - 1) * W * (H - 1);
ans %= mod;
return mem[H][W] = ans;
}
int main() {
memset(mem, -1, sizeof mem);
int H, W;
cin >> H >> W;
long long ans = dp(H, W) - 1;
if(ans < 0) ans += mod;
cout << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
35576 KB |
Output is correct |
2 |
Correct |
26 ms |
35692 KB |
Output is correct |
3 |
Correct |
26 ms |
35748 KB |
Output is correct |
4 |
Correct |
26 ms |
35748 KB |
Output is correct |
5 |
Correct |
32 ms |
35748 KB |
Output is correct |
6 |
Correct |
26 ms |
35868 KB |
Output is correct |
7 |
Correct |
34 ms |
36000 KB |
Output is correct |
8 |
Correct |
27 ms |
36000 KB |
Output is correct |
9 |
Correct |
27 ms |
36000 KB |
Output is correct |
10 |
Correct |
28 ms |
36000 KB |
Output is correct |
11 |
Correct |
31 ms |
36000 KB |
Output is correct |
12 |
Correct |
29 ms |
36000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
35576 KB |
Output is correct |
2 |
Correct |
26 ms |
35692 KB |
Output is correct |
3 |
Correct |
26 ms |
35748 KB |
Output is correct |
4 |
Correct |
26 ms |
35748 KB |
Output is correct |
5 |
Correct |
32 ms |
35748 KB |
Output is correct |
6 |
Correct |
26 ms |
35868 KB |
Output is correct |
7 |
Correct |
34 ms |
36000 KB |
Output is correct |
8 |
Correct |
27 ms |
36000 KB |
Output is correct |
9 |
Correct |
27 ms |
36000 KB |
Output is correct |
10 |
Correct |
28 ms |
36000 KB |
Output is correct |
11 |
Correct |
31 ms |
36000 KB |
Output is correct |
12 |
Correct |
29 ms |
36000 KB |
Output is correct |
13 |
Correct |
28 ms |
36000 KB |
Output is correct |
14 |
Correct |
27 ms |
36068 KB |
Output is correct |
15 |
Correct |
176 ms |
36112 KB |
Output is correct |
16 |
Correct |
27 ms |
36112 KB |
Output is correct |
17 |
Correct |
42 ms |
36112 KB |
Output is correct |
18 |
Correct |
66 ms |
36112 KB |
Output is correct |
19 |
Correct |
186 ms |
36112 KB |
Output is correct |
20 |
Correct |
151 ms |
36224 KB |
Output is correct |
21 |
Correct |
102 ms |
36224 KB |
Output is correct |
22 |
Correct |
106 ms |
36224 KB |
Output is correct |
23 |
Correct |
75 ms |
36224 KB |
Output is correct |
24 |
Correct |
239 ms |
36224 KB |
Output is correct |
25 |
Correct |
208 ms |
36224 KB |
Output is correct |
26 |
Correct |
210 ms |
36224 KB |
Output is correct |
27 |
Correct |
228 ms |
36224 KB |
Output is correct |