#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int MOD=1e9+7;
const int MAXN=3005;
int h,w;
long long dp[MAXN][MAXN];
long long fact[MAXN];
long long invF[MAXN];
int fastPow(long long x,int pwr)
{
long long ret=1;
while(pwr>0)
{
if(pwr&1) ret=ret*x%MOD;
pwr/=2;
x=x*x%MOD;
}
return ret;
}
int inverse(int x)
{
return fastPow(x,MOD-2);
}
void precomp()
{
for(int i=0;i<=w;i++) dp[0][i]=1;
for(int i=0;i<=h;i++) dp[i][0]=1;
for(int i=1;i<=h;i++)
{
for(int j=1;j<=w;j++)
{
dp[i][j]=(dp[i][j-1]+i*dp[i-1][j-1]*4)%MOD;
}
}
fact[0]=1;
for(int i=1;i<MAXN;i++) fact[i]=fact[i-1]*i%MOD;
for(int i=0;i<MAXN;i++) invF[i]=inverse(fact[i]);
}
int comb(int n,int k)
{
return (fact[n]*invF[n-k]%MOD)*invF[k]%MOD;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>h>>w;
precomp();
long long ans=0;
long long P1=1;
for(int r=0;r<=min(h,w/2);r++)
{
long long cur1=comb(h,r);
if(r>0) P1=P1*comb(w-2*r+2,2)%MOD;
cur1=cur1*P1%MOD;
long long P2=1;
for(int c=0;c<=min((h-r)/2,w-2*r);c++)
{
long long cur2=cur1*comb(w-2*r,c)%MOD;
if(c>0) P2=P2*comb(h-r-2*c+2,2)%MOD;
cur2=cur2*P2%MOD;
cur2=cur2*dp[h-r-2*c][w-2*r-c]%MOD;
ans+=cur2;
if(ans>=MOD) ans-=MOD;
}
}
cout<<ans-1<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
464 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
860 KB |
Output is correct |
6 |
Correct |
1 ms |
1372 KB |
Output is correct |
7 |
Correct |
1 ms |
860 KB |
Output is correct |
8 |
Correct |
1 ms |
1628 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Correct |
1 ms |
1884 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
464 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
860 KB |
Output is correct |
6 |
Correct |
1 ms |
1372 KB |
Output is correct |
7 |
Correct |
1 ms |
860 KB |
Output is correct |
8 |
Correct |
1 ms |
1628 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Correct |
1 ms |
1884 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
4 ms |
9820 KB |
Output is correct |
15 |
Correct |
55 ms |
55164 KB |
Output is correct |
16 |
Correct |
4 ms |
4188 KB |
Output is correct |
17 |
Correct |
11 ms |
12976 KB |
Output is correct |
18 |
Correct |
18 ms |
17244 KB |
Output is correct |
19 |
Correct |
69 ms |
63056 KB |
Output is correct |
20 |
Correct |
52 ms |
51024 KB |
Output is correct |
21 |
Correct |
34 ms |
33876 KB |
Output is correct |
22 |
Correct |
36 ms |
35420 KB |
Output is correct |
23 |
Correct |
20 ms |
27228 KB |
Output is correct |
24 |
Correct |
92 ms |
70932 KB |
Output is correct |
25 |
Correct |
63 ms |
61268 KB |
Output is correct |
26 |
Correct |
70 ms |
66648 KB |
Output is correct |
27 |
Correct |
76 ms |
69200 KB |
Output is correct |