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 <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
using namespace std;
typedef long long ll;
ll dp[4000][4000];
int main(){
int h,w;cin>>h>>w;
dp[0][w]=1;
rep(i,h)rep(j,w+1){
//0
(dp[i+1][j]+=dp[i][j])%=MOD;
//1
if(j)(dp[i+1][j-1]+=dp[i][j]*j*4)%=MOD;
//N-S
if(j&&i<h-1)(dp[i+2][j-1]+=dp[i][j]*j*(h-i-1))%=MOD;
//E-W
if(j>=2)(dp[i+1][j-2]+=dp[i][j]*(j*(j-1)/2))%=MOD;
}
ll ans=0;
rep(i,w+1)(ans+=dp[h][i])%=MOD;
cout<<(ans+MOD-1)%MOD<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |