This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
///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 (stderr)
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |