///usr/bin/g++ -O2 $0 -o ${0%.cpp} && echo "----------" && ./${0%.cpp}; exit;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int N = 3010;
const int mod = 1e9 + 7;
const int inv2 = (mod + 1) / 2;
int dp[N][N], H, W;
int mul(int a, int b) {
return (ll) a * b % mod;
}
void add(int &a, int b) {
a += b;
if(a >= mod) a -= mod;
}
int main() {
scanf("%d %d", &H, &W);
for(int w = 0; w <= W; w++) dp[0][w] = 1;
for(int h = 1; h <= H; h++) {
dp[h][0] = 1;
for(int w = 1; w <= W; w++) {
dp[h][w] = dp[h - 1][w];
add(dp[h][w], mul(mul(4, w), dp[h - 1][w - 1]));
if(w >= 2) add(dp[h][w], mul(mul(w, mul(w - 1, inv2)), dp[h - 1][w - 2]));
if(h >= 2) add(dp[h][w], mul(mul(w, h - 1), dp[h - 2][w - 1]));
}
}
dp[H][W] -= 1;
if(dp[H][W] < 0) dp[H][W] += mod;
printf("%d\n", dp[H][W]);
}
Compilation message
tents.cpp: In function 'int main()':
tents.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &H, &W);
~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
560 KB |
Output is correct |
4 |
Correct |
3 ms |
1388 KB |
Output is correct |
5 |
Correct |
3 ms |
1388 KB |
Output is correct |
6 |
Correct |
3 ms |
1460 KB |
Output is correct |
7 |
Correct |
3 ms |
1460 KB |
Output is correct |
8 |
Correct |
3 ms |
1612 KB |
Output is correct |
9 |
Correct |
2 ms |
1612 KB |
Output is correct |
10 |
Correct |
4 ms |
1880 KB |
Output is correct |
11 |
Correct |
2 ms |
1880 KB |
Output is correct |
12 |
Correct |
5 ms |
2156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
560 KB |
Output is correct |
4 |
Correct |
3 ms |
1388 KB |
Output is correct |
5 |
Correct |
3 ms |
1388 KB |
Output is correct |
6 |
Correct |
3 ms |
1460 KB |
Output is correct |
7 |
Correct |
3 ms |
1460 KB |
Output is correct |
8 |
Correct |
3 ms |
1612 KB |
Output is correct |
9 |
Correct |
2 ms |
1612 KB |
Output is correct |
10 |
Correct |
4 ms |
1880 KB |
Output is correct |
11 |
Correct |
2 ms |
1880 KB |
Output is correct |
12 |
Correct |
5 ms |
2156 KB |
Output is correct |
13 |
Correct |
2 ms |
2156 KB |
Output is correct |
14 |
Correct |
8 ms |
9888 KB |
Output is correct |
15 |
Correct |
111 ms |
33172 KB |
Output is correct |
16 |
Correct |
9 ms |
33172 KB |
Output is correct |
17 |
Correct |
29 ms |
33172 KB |
Output is correct |
18 |
Correct |
33 ms |
33172 KB |
Output is correct |
19 |
Correct |
118 ms |
34884 KB |
Output is correct |
20 |
Correct |
96 ms |
34884 KB |
Output is correct |
21 |
Correct |
65 ms |
34884 KB |
Output is correct |
22 |
Correct |
66 ms |
34884 KB |
Output is correct |
23 |
Correct |
44 ms |
34884 KB |
Output is correct |
24 |
Correct |
187 ms |
36040 KB |
Output is correct |
25 |
Correct |
117 ms |
36040 KB |
Output is correct |
26 |
Correct |
144 ms |
36040 KB |
Output is correct |
27 |
Correct |
150 ms |
36040 KB |
Output is correct |