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>
#define int long long
using namespace std;
#ifdef LOCAL
ifstream in("in.in");
ofstream out("out.out");
#else
#define in cin
#define out cout
#endif
const int nmax = 2005,mod = 1000000007;
int n,s,t;
int dp[nmax][nmax];
void addSelf(int &a, int b) {
a = (a + b) % mod;
}
int32_t main() {
in >> n >> s >> t;
if (s > t) {
swap(s,t);
}
dp[1][1] = 1;
for (int i = 2; i <= n; i++) {
for (int j = 1; j <= i; j++) {
if (i != s && i != t) {
addSelf(dp[i][j] , dp[i - 1][j - 1] * (j - (i > s) - (i > t)));
addSelf(dp[i][j] , dp[i - 1][j + 1] * j);
} else {
addSelf(dp[i][j] , dp[i - 1][j - 1]); // we can make a new group with just i, or add this to the left-most
addSelf(dp[i][j] , dp[i - 1][j]);
}
}
}
out << 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... |