#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
int add(int a, int b){
return (a+b)%MOD;
}
int mul(int a, int b){
return ((ll)a*b)%MOD;
}
int pw(int a, int b){
if(b == 0) return 1;
int res = pw(a, b/2);
res = mul(res, res);
if(b%2) res = mul(res, a);
return res;
}
int inv[3005];
int fact[3005];
int dp[3005][3005];
int bin(int n, int k){
if(n < 0 || k < 0 || n < k) return 0;
int res = fact[n];
res = mul(res, inv[n-k]);
res = mul(res, inv[k]);
return res;
}
int solve(int h, int w){
if(h < 0 || w < 0) return 0;
if(h == 0 || w == 0) return 1;
if(dp[h][w]) return dp[h][w];
/// hor. par
dp[h][w] = add(dp[h][w], mul(solve(h-1, w-2), w*(w-1)/2));
/// ver. par
dp[h][w] = add(dp[h][w], mul(solve(h-2, w-1), mul(w, h-1)));
/// samo jedan
dp[h][w] = add(dp[h][w], mul(4, mul(solve(h-1, w-1), w)));
/// nista
dp[h][w] = add(dp[h][w], solve(h-1, w));
return dp[h][w];
}
int main(){
ios_base::sync_with_stdio(false);
fact[0] = inv[0] = 1;
for(int i=1; i<=3000; i++){
fact[i] = mul(fact[i-1], i);
inv[i] = pw(fact[i], MOD-2);
}
int h, w;
cin >> h >> w;
cout << add(solve(h, w), MOD-1);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
2 ms |
1152 KB |
Output is correct |
5 |
Correct |
2 ms |
588 KB |
Output is correct |
6 |
Correct |
3 ms |
1228 KB |
Output is correct |
7 |
Correct |
2 ms |
724 KB |
Output is correct |
8 |
Correct |
3 ms |
1356 KB |
Output is correct |
9 |
Correct |
2 ms |
844 KB |
Output is correct |
10 |
Correct |
4 ms |
1612 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
5 ms |
1740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
2 ms |
1152 KB |
Output is correct |
5 |
Correct |
2 ms |
588 KB |
Output is correct |
6 |
Correct |
3 ms |
1228 KB |
Output is correct |
7 |
Correct |
2 ms |
724 KB |
Output is correct |
8 |
Correct |
3 ms |
1356 KB |
Output is correct |
9 |
Correct |
2 ms |
844 KB |
Output is correct |
10 |
Correct |
4 ms |
1612 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
5 ms |
1740 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
7 ms |
9676 KB |
Output is correct |
15 |
Correct |
305 ms |
29216 KB |
Output is correct |
16 |
Correct |
4 ms |
1484 KB |
Output is correct |
17 |
Correct |
26 ms |
4920 KB |
Output is correct |
18 |
Correct |
58 ms |
9280 KB |
Output is correct |
19 |
Correct |
345 ms |
30888 KB |
Output is correct |
20 |
Correct |
245 ms |
25412 KB |
Output is correct |
21 |
Correct |
128 ms |
16064 KB |
Output is correct |
22 |
Correct |
168 ms |
19968 KB |
Output is correct |
23 |
Correct |
128 ms |
19484 KB |
Output is correct |
24 |
Correct |
416 ms |
31988 KB |
Output is correct |
25 |
Correct |
303 ms |
27128 KB |
Output is correct |
26 |
Correct |
362 ms |
29768 KB |
Output is correct |
27 |
Correct |
408 ms |
31044 KB |
Output is correct |