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 mod = 1e9 + 7;
const int Nmax = 2010;
int n;
int S, T;
int f[Nmax][Nmax];
int main() {
cin >> n >> S >> T;
f[1][1] = 1;
for (int i = 1; i < n; ++i) {
for (int j = 1; j <= i; ++j) {
if (f[i][j] == 0) continue;
if (i + 1 == S || i + 1 == T) {
f[i + 1][j] += f[i][j];
f[i + 1][j + 1] += f[i][j];
if (f[i + 1][j] >= mod) f[i + 1][j] -= mod;
if (f[i + 1][j + 1] >= mod) f[i + 1][j + 1] -= mod;
} else {
f[i + 1][j - 1] += 1LL * f[i][j] * (j - 1) % mod;
if (f[i + 1][j - 1] >= mod) f[i + 1][j - 1] -= mod;
f[i + 1][j + 1] += 1LL * (j + 1 - (i + 1 > S) - (i + 1 > T)) * f[i][j] % mod;
if (f[i + 1][j + 1] >= mod) f[i + 1][j + 1] -= mod;
}
}
}
cout << f[n][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... |