#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MN = 3030;
const ll M = 1e9+7;
ll mul(ll a, ll b) {return (a*b)%M;}
ll dp[MN][MN];
ll ds(int h, int w) {
if(h == 0 || w == 0) {return 1;}
if(h < 0 || w < 0) {return 0;}
if(dp[h][w] != -1) {
return dp[h][w];
}
ll res = ds(h-1,w)+mul(4*w,ds(h-1,w-1));
if(h > 1) {
res += mul(w*(h-1),ds(h-2,w-1));
}
if(w > 1) {
res += mul(w*(w-1)/2,ds(h-1,w-2));
}
res %= M;
return dp[h][w] = res;
}
int main() {
ll h,w;
cin >> h >> w;
memset(dp,-1,sizeof(dp));
ll res = ds(h,w);
res--;
res = ((res%M)+M)%M;
cout << res << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
72192 KB |
Output is correct |
2 |
Correct |
38 ms |
72188 KB |
Output is correct |
3 |
Correct |
40 ms |
72184 KB |
Output is correct |
4 |
Correct |
40 ms |
72184 KB |
Output is correct |
5 |
Correct |
41 ms |
72184 KB |
Output is correct |
6 |
Correct |
40 ms |
72188 KB |
Output is correct |
7 |
Correct |
41 ms |
72184 KB |
Output is correct |
8 |
Correct |
40 ms |
72184 KB |
Output is correct |
9 |
Correct |
41 ms |
72192 KB |
Output is correct |
10 |
Correct |
42 ms |
72184 KB |
Output is correct |
11 |
Correct |
40 ms |
72244 KB |
Output is correct |
12 |
Correct |
42 ms |
72192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
72192 KB |
Output is correct |
2 |
Correct |
38 ms |
72188 KB |
Output is correct |
3 |
Correct |
40 ms |
72184 KB |
Output is correct |
4 |
Correct |
40 ms |
72184 KB |
Output is correct |
5 |
Correct |
41 ms |
72184 KB |
Output is correct |
6 |
Correct |
40 ms |
72188 KB |
Output is correct |
7 |
Correct |
41 ms |
72184 KB |
Output is correct |
8 |
Correct |
40 ms |
72184 KB |
Output is correct |
9 |
Correct |
41 ms |
72192 KB |
Output is correct |
10 |
Correct |
42 ms |
72184 KB |
Output is correct |
11 |
Correct |
40 ms |
72244 KB |
Output is correct |
12 |
Correct |
42 ms |
72192 KB |
Output is correct |
13 |
Correct |
40 ms |
72192 KB |
Output is correct |
14 |
Correct |
40 ms |
72312 KB |
Output is correct |
15 |
Correct |
195 ms |
72440 KB |
Output is correct |
16 |
Correct |
41 ms |
72192 KB |
Output is correct |
17 |
Correct |
54 ms |
72188 KB |
Output is correct |
18 |
Correct |
72 ms |
72312 KB |
Output is correct |
19 |
Correct |
221 ms |
72440 KB |
Output is correct |
20 |
Correct |
181 ms |
72440 KB |
Output is correct |
21 |
Correct |
119 ms |
72320 KB |
Output is correct |
22 |
Correct |
131 ms |
72392 KB |
Output is correct |
23 |
Correct |
101 ms |
72440 KB |
Output is correct |
24 |
Correct |
319 ms |
72440 KB |
Output is correct |
25 |
Correct |
210 ms |
72444 KB |
Output is correct |
26 |
Correct |
247 ms |
72440 KB |
Output is correct |
27 |
Correct |
291 ms |
72568 KB |
Output is correct |