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;
using ll = long long;
const int MOD = 1e9 + 7;
void norm(ll &x) {
if(x >= MOD) x -= MOD;
if(x < 0) x += MOD;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int h, w;
cin >> h >> w;
vector<vector<ll>> dp(w + 10, vector<ll>(w + 10));
dp[0][0] = 1;
for(ll i = 1; i <= h; i++) {
vector<vector<ll>> new_dp(w + 10, vector<ll>(w + 10));
for(ll j = 0; j <= w; j++) {
for(ll k = 0; k <= j; k++) {
ll val = dp[j][k];
if(!val) continue;
new_dp[j][k] += val,
norm(new_dp[j][k]);
new_dp[j + 2][k] += (w - j) * (w - j - 1) / 2 * val % MOD,
norm(new_dp[j + 2][k]);
new_dp[j + 1][k] += (w - j) * 4 * val % MOD;
norm(new_dp[j + 1][k]);
new_dp[j + 1][k + 1] += val * (w - j) % MOD;
norm(new_dp[j + 1][k + 1]);
if(!k) continue;
new_dp[j][k - 1] += val * k % MOD;
norm(new_dp[j][k - 1]);
}
}
dp = new_dp;
}
ll ans = 0;
for(int j = 1; j <= w; j++) ans += dp[j][0], norm(ans);
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |