#include<bits/stdc++.h>
using namespace std;
#define task "a"
#define se second
#define fi first
#define ll long long
#define ii pair<ll, ll>
const long mxN = 3e3 + 7, MOD = 1e9 + 7;
ll gt[mxN], rev[mxN], f[mxN][mxN], sum[mxN][mxN];
int nRow, nCol;
ll pw(ll j, int mx)
{
if (!mx)
return 1;
ll res = pw(j, mx / 2);
res = res * res % MOD;
if (mx % 2)
return res * j % MOD;
return res;
}
ll C(int u, int v)
{
if (u > v)
return 0;
return gt[v] * rev[u] % MOD * rev[v - u] % MOD;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//freopen(task".INP", "r", stdin);
//freopen(task".OUT", "w", stdout);
cin >> nRow >> nCol;
int mxn = max(nRow, nCol);
gt[0] = rev[0] = 1;
for (int i = 1; i <= mxn; i++)
{
gt[i] = gt[i - 1] * i % MOD;
rev[i] = pw(gt[i], MOD - 2);
}
for (int i = 0; i <= mxn; i++)
{
sum[0][i] = f[0][i] = 1;
for (int j = 1; j <= i; j++)
{
f[j][i] = f[j - 1][i] * C(2, i - j * 2 + 2) % MOD;
sum[j][i] = sum[j - 1][i - 1] * i * 4 % MOD + sum[j - 1][i];
sum[j][i] %= MOD;
}
}
ll ans = 0;
for (int i = 0; i <= nRow; i++)
{
for (int j = 0; j <= nCol; j++)
{
int Row = nRow - 2 * i - j;
int Col = nCol - 2 * j - i;
if (Row > Col)
swap(Row, Col);
if (Row < 0)
break;
ll inc = f[i][nRow] * f[j][nCol] % MOD * C(i, nCol - 2 * j) % MOD * C(j, nRow - 2 * i) % MOD;
inc = inc * sum[Row][Col] % MOD;
ans = (ans + inc) % MOD;
}
}
cout << (ans + MOD - 1) % MOD;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |