이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
const int N = 3e3 + 5;
const int mod = 1e9 + 7;
ll dp1[N][N], dp2[N];
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int h, w;
cin >> h >> w;
dp1[0][w] = 1;
for (int i = 0; i < h; i++) {
for (int j = w; j >= 0; j--) {
if (j >= 2) {
dp1[i + 1][j - 2] += ((j * (j - 1) / 2) % mod) * dp1[i][j];
dp1[i + 1][j - 2] %= mod;
}
if (j >= 1) {
dp1[i + 1][j - 1] += j * dp2[j] + 4 * j * dp1[i][j];
dp1[i + 1][j - 1] %= mod;
}
dp1[i + 1][j] += dp1[i][j];
dp1[i + 1][j] %= mod;
dp2[j] += (i + 1) * dp1[i][j] - i * dp1[max(i - 1, 0)][j];
dp2[j] %= mod;
}
}
ll ans = 0;
for (int i = 0; i < w; i++) {
ans += dp1[h][i];
ans %= mod;
}
cout << ans << "\n";
// for (int i = 0; i <= h; i++) {
// for (int j = w; j >= 0; j--) cout << dp1[i][j] << " ";
// cout << "\n";
// }
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |