#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;
const int MOD = 1e9 + 7;
i64 mod_pow(i64 x, i64 n = MOD - 2) {
i64 ret = 1;
while(n) {
if(n & 1) (ret *= x) %= MOD;
(x *= x) %= MOD;
n >>= 1;
}
return ret;
}
std::vector<i64> fact, inv;
i64 comb(int n, int r) {
return fact[n] * inv[n - r] % MOD * inv[r] % MOD;
}
int main() {
int h, w; scanf("%d%d", &h, &w);
// assert(h <= 300 and w <= 300);
fact.assign(std::max(h, w) + 1, 1); inv.assign(std::max(h, w) + 1, 1);
for(int i = 0; i < std::max(h, w); i++) fact[i + 1] = fact[i] * (i64)(i + 1) % MOD;
for(int i = 0; i <= std::max(h, w); i++) inv[i] = mod_pow(fact[i]);
std::vector<std::vector<i64>> dp(h + 1, std::vector<i64>(w + 1, 0));
dp[h][w] = 1;
for(i64 i = h; i >= 0; i--) {
for(i64 j = w; j >= 0; j--) {
if(i >= 1 and j >= 1) {
dp[i - 1][j - 1] += dp[i][j] * j % MOD * 4;
dp[i - 1][j - 1] %= MOD;
}
if(i >= 1 and j >= 2) {
dp[i - 1][j - 2] += dp[i][j] * comb(j, 2) % MOD;
dp[i - 1][j - 2] %= MOD;
}
if(i >= 2 and j >= 1) {
dp[i - 2][j - 1] += dp[i][j] * j % MOD * (i - 1) % MOD;
dp[i - 2][j - 1] %= MOD;
}
if(i >= 1) {
dp[i - 1][j] += dp[i][j];
dp[i - 1][j] %= MOD;
}
}
}
i64 ans = 0;
for(int j = 0; j <= w; j++) (ans += dp[0][j]) %= MOD;
printf("%lld\n", (ans - 1 + MOD) % MOD);
return 0;
}
Compilation message
tents.cpp: In function 'int main()':
tents.cpp:26:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int h, w; scanf("%d%d", &h, &w);
~~~~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
0 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
640 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
7 ms |
1024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
0 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
640 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
7 ms |
1024 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
512 KB |
Output is correct |
15 |
Correct |
207 ms |
44296 KB |
Output is correct |
16 |
Correct |
14 ms |
3200 KB |
Output is correct |
17 |
Correct |
41 ms |
10212 KB |
Output is correct |
18 |
Correct |
58 ms |
12544 KB |
Output is correct |
19 |
Correct |
207 ms |
51448 KB |
Output is correct |
20 |
Correct |
179 ms |
41336 KB |
Output is correct |
21 |
Correct |
153 ms |
27264 KB |
Output is correct |
22 |
Correct |
112 ms |
27008 KB |
Output is correct |
23 |
Correct |
60 ms |
15096 KB |
Output is correct |
24 |
Correct |
312 ms |
71032 KB |
Output is correct |
25 |
Correct |
234 ms |
52764 KB |
Output is correct |
26 |
Correct |
269 ms |
60536 KB |
Output is correct |
27 |
Correct |
323 ms |
68288 KB |
Output is correct |