#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod = 1e9 + 7;
ll dp[3005][3005];
ll DP(int i , int j){
if(i < 0 || j < 0) return 0;
if(i == 0 || j == 0) return 1;
ll &ret = dp[i][j];
if(ret != -1) return ret;
ret = 0;
ret += 4 * j * DP(i - 1 , j - 1) % mod;
ret %= mod;
ret += DP(i - 1 , j) % mod;
ret %= mod;
ret += (j * (j - 1))/2 * DP(i - 1 , j - 2) % mod;
ret %= mod;
ret += j * (i - 1) * DP(i - 2 , j - 1) % mod;
ret %= mod;
return ret;
}
int main (){
ios_base::sync_with_stdio(0); cin.tie(0);
int h , w;
cin >> h >> w;
memset(dp , -1 , sizeof(dp));
cout << (DP(h , w) + mod - 1) % mod;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
71032 KB |
Output is correct |
2 |
Correct |
41 ms |
71032 KB |
Output is correct |
3 |
Correct |
43 ms |
71032 KB |
Output is correct |
4 |
Correct |
41 ms |
71056 KB |
Output is correct |
5 |
Correct |
45 ms |
71076 KB |
Output is correct |
6 |
Correct |
47 ms |
71012 KB |
Output is correct |
7 |
Correct |
41 ms |
71032 KB |
Output is correct |
8 |
Correct |
40 ms |
71032 KB |
Output is correct |
9 |
Correct |
44 ms |
71012 KB |
Output is correct |
10 |
Correct |
51 ms |
71032 KB |
Output is correct |
11 |
Correct |
39 ms |
71040 KB |
Output is correct |
12 |
Correct |
47 ms |
71148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
71032 KB |
Output is correct |
2 |
Correct |
41 ms |
71032 KB |
Output is correct |
3 |
Correct |
43 ms |
71032 KB |
Output is correct |
4 |
Correct |
41 ms |
71056 KB |
Output is correct |
5 |
Correct |
45 ms |
71076 KB |
Output is correct |
6 |
Correct |
47 ms |
71012 KB |
Output is correct |
7 |
Correct |
41 ms |
71032 KB |
Output is correct |
8 |
Correct |
40 ms |
71032 KB |
Output is correct |
9 |
Correct |
44 ms |
71012 KB |
Output is correct |
10 |
Correct |
51 ms |
71032 KB |
Output is correct |
11 |
Correct |
39 ms |
71040 KB |
Output is correct |
12 |
Correct |
47 ms |
71148 KB |
Output is correct |
13 |
Correct |
42 ms |
71032 KB |
Output is correct |
14 |
Correct |
42 ms |
71160 KB |
Output is correct |
15 |
Correct |
282 ms |
71268 KB |
Output is correct |
16 |
Correct |
50 ms |
71016 KB |
Output is correct |
17 |
Correct |
63 ms |
71032 KB |
Output is correct |
18 |
Correct |
87 ms |
71140 KB |
Output is correct |
19 |
Correct |
289 ms |
71244 KB |
Output is correct |
20 |
Correct |
243 ms |
71264 KB |
Output is correct |
21 |
Correct |
152 ms |
71168 KB |
Output is correct |
22 |
Correct |
170 ms |
71168 KB |
Output is correct |
23 |
Correct |
123 ms |
71276 KB |
Output is correct |
24 |
Correct |
392 ms |
71248 KB |
Output is correct |
25 |
Correct |
296 ms |
71160 KB |
Output is correct |
26 |
Correct |
344 ms |
71240 KB |
Output is correct |
27 |
Correct |
364 ms |
71168 KB |
Output is correct |