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 int long long
using namespace std;
const int MOD = 1000000007;
signed main(){
int h, w;
cin>>h>>w;
int dp[h+1][w+1];
dp[1][1] = 5;
for(int i = 0;i<=h;i++) dp[i][0] = 1;
for(int i = 0;i<=w;i++) dp[0][i] = 1;
for(int i = 2;i<=h;i++){
dp[i][1] = dp[i-1][1] + (i-1) + 4;
}
for(int j = 2;j<=w;j++){
for(int i = 1;i<=h;i++){
dp[i][j] = dp[i][j-1];
dp[i][j]%=MOD;
dp[i][j] += (((i*(j-1))%MOD)*dp[i-1][j-2])%MOD;
dp[i][j]%=MOD;
dp[i][j] += (4*i*dp[i-1][j-1])%MOD;
dp[i][j]%=MOD;
if(i>1) dp[i][j] += ((((i*(i-1))/2)%MOD) * (dp[i-2][j-1]))%MOD;
dp[i][j]%=MOD;
}
}
int ans = (dp[h][w] - 1 + MOD)%MOD;
cout<<ans<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |