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 <iostream>
typedef long long ll;
using namespace std;
const int mod = 1e9 + 7, maxn = 3005;
int add(const int& a, const int& b) { return (a + b) % mod; }
int mul(const int& a, const int& b) { return (a * 1ll * b) % (ll)mod; }
void upd(int& a, const int& b) { a = (a + b) % mod; }
int dp[maxn][maxn], p[maxn][maxn];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
p[0][0] = 1;
for (int i = 1; i < maxn; i++)
{
p[i][0] = p[i][i] = 1;
for (int j = 1; j < i; j++) p[i][j] = add(p[i - 1][j - 1], p[i - 1][j]);
}
dp[0][0] = 1;
int h, w;
cin >> h >> w;
for (int i = 0; i < h; i++) for (int j = 0; j < w; j++)
{
upd(dp[i + 1][j + 1], mul(dp[i][j], mul(4, j + 1)));
if (i + 2 <= h) upd(dp[i + 2][j + 1], mul(dp[i][j], mul(i + 1, j + 1)));
if (j + 2 <= w) upd(dp[i + 1][j + 2], mul(dp[i][j], (j + 1) * (j + 2)/ 2));
}
int ans = 0;
for (int i = 1; i <= h; i++) for (int j = 1; j <= w; j++)
{
int a = mul(dp[i][j], mul(p[h][i], p[w][j]));
upd(ans, a);
}
cout << ans << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |