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;
const int N = 2005;
const int mod = 1e9 + 7;
int n, st, ed;
int f[N][N];
void add(int &x, int y) {
x = (x + y) >= mod ? x + y - mod : x + y;
}
int main() {
ios::sync_with_stdio(false);
cin >> n >> st >> ed;
f[1][0] = 1;
for (int i = 1; i <= n; ++i) {
for (int j = 0; j <= i; ++j) {
if (!f[i][j]) continue;
if (i == st || i == ed) {
if (j) add(f[i + 1][j], f[i][j]);
add(f[i + 1][j + 1], f[i][j]);
}
else {
if (j >= 2) add(f[i + 1][j - 1], 1LL * f[i][j] * (j - 1) % mod);
int k = j - (i > st) - (i > ed) + 1;
if (k > 0) add(f[i + 1][j + 1], 1LL * f[i][j] * k % mod);
}
}
}
cout << f[n + 1][1];
}
# | 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... |