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 mod = 1000000007;
const int N = 2008;
int dp[N][N];
int32_t main() {
int n, s, e, ep = 0;
cin >> n >> s >> e;
dp[1][1] = 1;
if (s == 1 || e == 1) ep++;
for (int i = 2; i <= n; i++) {
for (int j = 1; j <= i; j++) {
if (i == s || i == e) {
ep++;
dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j]) % mod;
} else {
dp[i][j] = (dp[i - 1][j - 1] * (j - ep) % mod + dp[i - 1][j + 1] * j % mod) % mod;
}
}
}
cout << dp[n][1] << '\n';
}
# | 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... |