#include <bits/stdc++.h>
#define N 3030
#define mod (1000000007)
using namespace std;
typedef long long ll;
ll H, W, dp[N][N];
ll solve(int lf, int cf)
{
if(lf < 0 || cf < 0) return 0;
if(!lf || !cf) return 1;
if(dp[lf][cf] != -1) return dp[lf][cf];
ll nao_coloca = solve(lf - 1, cf), coloca1 = solve(lf - 1, cf - 1)*4*cf;
ll coloca2 = solve(lf - 1, cf - 2)*cf*(cf - 1)/2, coloca2row = solve(lf - 2, cf - 1)*cf*(lf - 1);
return dp[lf][cf] = (nao_coloca + coloca1 + coloca2 + coloca2row)%mod;
}
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
cin>>H>>W;
memset(dp, -1, sizeof dp);
cout<<(solve(H, W) + mod - 1)%mod<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
72184 KB |
Output is correct |
2 |
Correct |
54 ms |
72204 KB |
Output is correct |
3 |
Correct |
54 ms |
72204 KB |
Output is correct |
4 |
Correct |
54 ms |
72276 KB |
Output is correct |
5 |
Correct |
55 ms |
72308 KB |
Output is correct |
6 |
Correct |
57 ms |
72436 KB |
Output is correct |
7 |
Correct |
57 ms |
72436 KB |
Output is correct |
8 |
Correct |
55 ms |
72496 KB |
Output is correct |
9 |
Correct |
55 ms |
72496 KB |
Output is correct |
10 |
Correct |
56 ms |
72496 KB |
Output is correct |
11 |
Correct |
54 ms |
72496 KB |
Output is correct |
12 |
Correct |
61 ms |
72496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
72184 KB |
Output is correct |
2 |
Correct |
54 ms |
72204 KB |
Output is correct |
3 |
Correct |
54 ms |
72204 KB |
Output is correct |
4 |
Correct |
54 ms |
72276 KB |
Output is correct |
5 |
Correct |
55 ms |
72308 KB |
Output is correct |
6 |
Correct |
57 ms |
72436 KB |
Output is correct |
7 |
Correct |
57 ms |
72436 KB |
Output is correct |
8 |
Correct |
55 ms |
72496 KB |
Output is correct |
9 |
Correct |
55 ms |
72496 KB |
Output is correct |
10 |
Correct |
56 ms |
72496 KB |
Output is correct |
11 |
Correct |
54 ms |
72496 KB |
Output is correct |
12 |
Correct |
61 ms |
72496 KB |
Output is correct |
13 |
Correct |
54 ms |
72496 KB |
Output is correct |
14 |
Correct |
56 ms |
72540 KB |
Output is correct |
15 |
Correct |
218 ms |
72700 KB |
Output is correct |
16 |
Correct |
53 ms |
72700 KB |
Output is correct |
17 |
Correct |
69 ms |
72700 KB |
Output is correct |
18 |
Correct |
100 ms |
72700 KB |
Output is correct |
19 |
Correct |
237 ms |
72700 KB |
Output is correct |
20 |
Correct |
199 ms |
72700 KB |
Output is correct |
21 |
Correct |
144 ms |
72700 KB |
Output is correct |
22 |
Correct |
148 ms |
72700 KB |
Output is correct |
23 |
Correct |
111 ms |
72700 KB |
Output is correct |
24 |
Correct |
314 ms |
72708 KB |
Output is correct |
25 |
Correct |
235 ms |
72708 KB |
Output is correct |
26 |
Correct |
284 ms |
72708 KB |
Output is correct |
27 |
Correct |
308 ms |
72800 KB |
Output is correct |