#include <bits/stdc++.h>
#define TASK "flagger"
#define INT_LIM (int) 2147483647
#define LL_LIM (long long) 9223372036854775807
#define endl '\n'
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define BIT(i,x) (((i)>>(x))&1)
#define FOR(i,a,b) for(int i = (a); i<=(b); i++)
#define FORD(i,a,b) for(int i = (a); i>=(b); i--)
#define ll long long
#define pii pair<int,int>
using namespace std;
///------------------------------------------///
const int MOD = 1e9+7;
int fact[5001], inv[5001];
int pw(int x, int p)
{
int ret = 1;
while (p>0)
{
if (p&1) ret = 1LL*ret*x%MOD;
x = 1LL*x*x%MOD; p>>=1;
}
return ret;
}
void prep(int MAXN)
{
fact[0] = 1;
FOR(i, 1, MAXN) fact[i] = 1LL*fact[i-1]*i%MOD;
inv[MAXN] = pw(fact[MAXN], MOD-2);
FORD(i, MAXN, 1) inv[i-1] = 1LL*inv[i]*i%MOD;
}
int nCk(int n, int k)
{
if (k<0 || k>n) return 0;
return 1LL*fact[n]*inv[n-k]%MOD*inv[k]%MOD;
}
void add(int &x, const int &y)
{
x+=y;
if (x>=MOD) x-=MOD;
}
int n,m;
void inp()
{
cin >> n >> m;
prep(max(n,m));
}
int f[5001][5001];
int chia2;
int pw2[5001];
void solve()
{
FOR(i, 0, n) f[i][0] = 1;
FOR(j, 0, m) f[0][j] = 1;
FOR(i, 1, n) FOR(j, 1, m)
{
f[i][j] = f[i][j-1];
if (i>=2) add(f[i][j], 1LL*nCk(i, 2)*f[i-2][j-1]%MOD);
}
chia2 = pw(2, MOD-2);
pw2[0] = 1;
FOR(i, 1, 5000) pw2[i] = 1LL*pw2[i-1]*chia2%MOD;
int ans = 0;
int pw4 = 1;
FOR(k, 0, min(n,m))
{
int term1 = 1LL*nCk(n,k)*nCk(m,k)%MOD*fact[k]%MOD*pw4%MOD;
FOR(l, 0, min(n-k, (m-k)/2))
{
int term2 = 1LL*nCk(n-k,l)*nCk(m-k,2*l)%MOD*fact[2*l]%MOD;
term2 = 1LL*term2*pw2[l]%MOD;
add(ans, 1LL*term1*term2%MOD*f[n-k-l][m-k-2*l]%MOD);
}
pw4 = 1LL*pw4*4%MOD;
}
ans--; if (ans<0) ans+=MOD;
cout << ans;
}
signed main()
{
///--------------------------///
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
if (fopen(TASK".INP","r")!=NULL)
{
freopen(TASK".INP","r",stdin);
freopen(TASK".OUT","w",stdout);
}
///--------------------------///
int NTEST = 1;
//cin >> NTEST;
while (NTEST--)
{
inp();
solve();
}
return 0;
}
///------------------------------------------///
Compilation message (stderr)
tents.cpp: In function 'int main()':
tents.cpp:97:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
97 | freopen(TASK".INP","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
tents.cpp:98:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
98 | freopen(TASK".OUT","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |