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 = 1000 * 1000 * 1000 + 7;
int main()
{
cin.tie(nullptr)->sync_with_stdio(0);
int h, w;
cin >> h >> w;
vector<vector<long long>> dp(h + 1, vector<long long>(w + 1));
auto C2 = [](int x) {
return x * (x - 1) / 2;
};
for(int i = 0; i <= h; i++) {
for(int j = 0; j <= w; j++) {
if(i == 0 || j == 0) {
dp[i][j] = 1;
continue;
}
dp[i][j] += dp[i][j - 1];
dp[i][j] += 4ll * i * dp[i - 1][j - 1];
if(i >= 2) {
dp[i][j] += C2(i) * dp[i - 2][j - 1];
}
if(j >= 2) {
dp[i][j] += i * (j - 1) * dp[i - 1][j - 2];
}
dp[i][j] %= mod;
}
}
cout << (dp[h][w] - 1 + mod) % mod << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |