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 int long long
const int N = 2005, M = 1e9 + 7;
int add(int a, int b) { return (a + b + 2 * M) % M; }
int mul(int a, int b) { return (a * b) % M; }
int n, s, e, mem[N][N];
int dp(int i, int j) {
if (i == n) return j == 1;
auto &ret = mem[i][j];
if (~ret) return ret;
if (i == s || i == e) {
ret = dp(i + 1, j);
ret = add(ret, dp(i + 1, j + 1));
} else {
ret = mul(dp(i + 1, j + 1), j + 1);
if (j > 1) ret = add(ret, mul(dp(i + 1, j - 1), j - 1)) % M;
}
return ret;
}
void solve() {
memset(mem, -1, sizeof mem);
cin >> n >> s >> e;
--s, --e;
cout << dp(0, 0) << '\n';
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int tc = 1;
// cin >> tc;
for (int i = 1; i <= tc; ++i) {
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |