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 <iostream>
using namespace std;
const int N = 2000 + 5;
const int Mod = 1e9 + 7;
int n, s, e, dp[N][N];
int main() {
cin >> n >> s >> e;
dp[0][0] = 1;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= i; ++j) {
if(i == s || i == e) {
dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j];
} else {
dp[i][j] = (1LL * dp[i - 1][j + 1] * j % Mod + 1LL * dp[i - 1][j - 1] * (j - (i > s) - (i > e)) % Mod);
}
if(dp[i][j] >= Mod) dp[i][j] -= Mod;
}
}
cout << dp[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... |