#include <iostream>
#include <cstring>
using namespace std;
#define ll long long
#define MOD 1000000007
ll dp[3005][3005];
ll go(int x, int y)
{
if(x == 0 || y == 0)
return 1;
ll& ret = dp[x][y];
if(ret != -1)
return ret;
ret = 0;
ret += go(x-1, y);
ret %= MOD;
if(y > 0)
ret += 4*y*go(x-1, y-1) % MOD;
ret %= MOD;
if(x > 1 && y > 0)
ret += (x-1)*y*go(x-2, y-1) % MOD;
ret %= MOD;
if(y > 1)
ret += (y*(y-1))/2 % MOD * go(x-1, y-2);
ret %= MOD;
return ret;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
memset(dp, -1, sizeof(dp));
int h, w;
cin >> h >> w;
cout << (go(h, w) - 1 + MOD) % MOD << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
71256 KB |
Output is correct |
2 |
Correct |
9 ms |
71004 KB |
Output is correct |
3 |
Correct |
9 ms |
71004 KB |
Output is correct |
4 |
Correct |
9 ms |
71068 KB |
Output is correct |
5 |
Correct |
10 ms |
70900 KB |
Output is correct |
6 |
Correct |
9 ms |
71004 KB |
Output is correct |
7 |
Correct |
9 ms |
71004 KB |
Output is correct |
8 |
Correct |
9 ms |
71004 KB |
Output is correct |
9 |
Correct |
9 ms |
71004 KB |
Output is correct |
10 |
Correct |
10 ms |
71076 KB |
Output is correct |
11 |
Correct |
10 ms |
71004 KB |
Output is correct |
12 |
Correct |
11 ms |
71088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
71256 KB |
Output is correct |
2 |
Correct |
9 ms |
71004 KB |
Output is correct |
3 |
Correct |
9 ms |
71004 KB |
Output is correct |
4 |
Correct |
9 ms |
71068 KB |
Output is correct |
5 |
Correct |
10 ms |
70900 KB |
Output is correct |
6 |
Correct |
9 ms |
71004 KB |
Output is correct |
7 |
Correct |
9 ms |
71004 KB |
Output is correct |
8 |
Correct |
9 ms |
71004 KB |
Output is correct |
9 |
Correct |
9 ms |
71004 KB |
Output is correct |
10 |
Correct |
10 ms |
71076 KB |
Output is correct |
11 |
Correct |
10 ms |
71004 KB |
Output is correct |
12 |
Correct |
11 ms |
71088 KB |
Output is correct |
13 |
Correct |
9 ms |
71004 KB |
Output is correct |
14 |
Correct |
9 ms |
71260 KB |
Output is correct |
15 |
Correct |
105 ms |
71372 KB |
Output is correct |
16 |
Correct |
10 ms |
71004 KB |
Output is correct |
17 |
Correct |
19 ms |
71212 KB |
Output is correct |
18 |
Correct |
30 ms |
71004 KB |
Output is correct |
19 |
Correct |
118 ms |
71384 KB |
Output is correct |
20 |
Correct |
92 ms |
71256 KB |
Output is correct |
21 |
Correct |
58 ms |
71132 KB |
Output is correct |
22 |
Correct |
64 ms |
71256 KB |
Output is correct |
23 |
Correct |
42 ms |
71260 KB |
Output is correct |
24 |
Correct |
146 ms |
71256 KB |
Output is correct |
25 |
Correct |
125 ms |
71260 KB |
Output is correct |
26 |
Correct |
126 ms |
71256 KB |
Output is correct |
27 |
Correct |
139 ms |
71260 KB |
Output is correct |