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"
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
ll MOD = 1e9+7;
int h, w;
ll dp[3010][3010];
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
#ifdef LOCAL_DEFINE
freopen("input.txt", "r", stdin);
#endif
cin >> h >> w;
for(int i = 0; i <= w; i++){
dp[0][i] = 1;
}
for(int i = 0; i <= h; i++){
dp[i][0] = 1;
}
//memset(dp, 0, sizeof dp);
for(int i = 1; i <= h; i++){
for(int j = 1; j <= w; j++){
dp[i][j] += dp[i-1][j];
dp[i][j] += 4*j*dp[i-1][j-1];
if(j>1) dp[i][j] += j*(j-1)/2*dp[i-1][j-2];
if(i>1) dp[i][j] += j*(i-1)*dp[i-2][j-1];
dp[i][j] %= MOD;
}
}
cout << dp[h][w]-1 % MOD << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |