#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
const int N = 3010;
const int MOD = 1e9 + 7;
inline int add(int a, int b) {
if(a + b < MOD) return a + b;
return a + b - MOD;
}
inline int mult(int a, int b) {
return (ll) a * b % MOD;
}
inline int pot(int a, int b) {
int ret = 1;
for(; b; b /= 2, a = mult(a, a))
if(b & 1) ret = mult(ret, a);
return ret;
}
inline int inv(int a) {
return pot(a, MOD - 2);
}
int w, h;
int C[N][N], F[N][N];
int f(int a, int b) {
if(!a || !b) return 1;
if(F[a][b] != -1) return F[a][b];
return F[a][b] = add(mult(mult(4, a), f(a - 1, b - 1)), f(a, b - 1));
}
int c(int a, int b) {
if(a == b || !b) return 1;
if(C[a][b] != -1) return C[a][b];
return C[a][b] = add(c(a - 1, b), c(a - 1, b - 1));
}
int main() {
memset(C, -1, sizeof(C));
memset(F, -1, sizeof(F));
scanf("%d%d", &h, &w);
int ans = MOD - 1;
for(int n = 0; n <= w && h >= 2 * n; ++n) {
int v = c(w, n);
for(int i = 0; i < n; ++i) v = mult(v, c(h - 2 * i, 2));
int prod = 1;
for(int m = 0; m <= h && h >= 2 * n + m && w >= 2 * m + n; ++m) {
ans = add(ans, mult(v, mult(mult(c(h - 2 * n, m), prod), f(w - n - 2 * m, h - 2 * n - m))));
prod = mult(prod, c(w - n - 2 * m, 2));
}
}
printf("%d\n", ans);
return 0;
}
Compilation message
tents.cpp: In function 'int main()':
tents.cpp:51:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
51 | scanf("%d%d", &h, &w);
| ~~~~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
71256 KB |
Output is correct |
2 |
Correct |
9 ms |
71260 KB |
Output is correct |
3 |
Correct |
9 ms |
71260 KB |
Output is correct |
4 |
Correct |
9 ms |
71260 KB |
Output is correct |
5 |
Correct |
9 ms |
71260 KB |
Output is correct |
6 |
Correct |
9 ms |
71296 KB |
Output is correct |
7 |
Correct |
9 ms |
71260 KB |
Output is correct |
8 |
Correct |
9 ms |
71260 KB |
Output is correct |
9 |
Correct |
10 ms |
71260 KB |
Output is correct |
10 |
Correct |
15 ms |
71260 KB |
Output is correct |
11 |
Correct |
8 ms |
71280 KB |
Output is correct |
12 |
Correct |
12 ms |
71260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
71256 KB |
Output is correct |
2 |
Correct |
9 ms |
71260 KB |
Output is correct |
3 |
Correct |
9 ms |
71260 KB |
Output is correct |
4 |
Correct |
9 ms |
71260 KB |
Output is correct |
5 |
Correct |
9 ms |
71260 KB |
Output is correct |
6 |
Correct |
9 ms |
71296 KB |
Output is correct |
7 |
Correct |
9 ms |
71260 KB |
Output is correct |
8 |
Correct |
9 ms |
71260 KB |
Output is correct |
9 |
Correct |
10 ms |
71260 KB |
Output is correct |
10 |
Correct |
15 ms |
71260 KB |
Output is correct |
11 |
Correct |
8 ms |
71280 KB |
Output is correct |
12 |
Correct |
12 ms |
71260 KB |
Output is correct |
13 |
Correct |
9 ms |
71256 KB |
Output is correct |
14 |
Correct |
9 ms |
71260 KB |
Output is correct |
15 |
Correct |
120 ms |
71492 KB |
Output is correct |
16 |
Correct |
13 ms |
71256 KB |
Output is correct |
17 |
Correct |
21 ms |
71380 KB |
Output is correct |
18 |
Correct |
48 ms |
71260 KB |
Output is correct |
19 |
Correct |
152 ms |
71492 KB |
Output is correct |
20 |
Correct |
110 ms |
71464 KB |
Output is correct |
21 |
Correct |
83 ms |
71412 KB |
Output is correct |
22 |
Correct |
77 ms |
71448 KB |
Output is correct |
23 |
Correct |
42 ms |
71512 KB |
Output is correct |
24 |
Correct |
183 ms |
71500 KB |
Output is correct |
25 |
Correct |
146 ms |
71476 KB |
Output is correct |
26 |
Correct |
159 ms |
71484 KB |
Output is correct |
27 |
Correct |
167 ms |
71492 KB |
Output is correct |