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>
#include <fstream>
using namespace std;
const long long mod=1000*1000*1000+7;
long long dp[3005][3005];
int h,w;
long long i,j;
int main()
{
// freopen("data.in","r",stdin);
cin>>h>>w;
for(i=0;i<=max(h,w);i++)
dp[i][0]=dp[0][i]=1;
for(i=1;i<=h;i++)
{
for(j=1;j<=w;j++)
{
dp[i][j]+=(1LL*dp[i-1][j])%mod;
if(j>=2)dp[i][j]+=(1LL*dp[i-1][j-2]*j*(j-1)/2)%mod;
if(i>=2)dp[i][j]+=(dp[i-2][j-1]*1LL*(i-1)*j)%mod;
dp[i][j]+=(dp[i-1][j-1]*4*j)%mod;
dp[i][j]%=mod;
}
}
cout<<(dp[h][w]-1+mod)%mod;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |