This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
void add(int& a, int b) {
a += b, a -= a >= MOD ? MOD : 0;
}
int main() {
int H, W;
cin >> H >> W;
int dp[H + 1][W + 1] = {};
for (int N = 0; N <= H; N++) {
for (int M = 0; M <= W; M++) {
if (N == 0 || M == 0) {
dp[N][M] = 1;
continue;
}
add(dp[N][M], dp[N - 1][M]);
if (N > 0 && M > 0) {
add(dp[N][M], 4ll * dp[N - 1][M - 1] * M % MOD);
if (N > 1) {
add(dp[N][M], 1ll * dp[N - 2][M - 1] * (N - 1) % MOD * M % MOD);
}
if (M > 1) {
add(dp[N][M], 1ll * dp[N - 1][M - 2] * (1ll * M * (M - 1) / 2 % MOD) % MOD);
}
}
}
}
add(dp[H][W], MOD - 1);
cout << dp[H][W] << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |