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