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 ll = long long;
using namespace std;
const int md = 1000000007;
const int mxN = 2003;
ll dp[mxN][mxN];
int main() {
int N, cs, cf;
cin >> N >> cs >> cf;
dp[1][1] = 1;
int fixed = 0;
for (int i = 1; i <= N; i ++) {
if (i == cs) {
fixed ++;
}
if (i == cf) {
fixed ++;
}
if (i ^ 1) {
for (int j = 1; j <= i; j ++) {
if (i ^ cs && i ^ cf) {
(dp[i][j] += dp[i - 1][j - 1] * (j - fixed) % md) %= md;
(dp[i][j] += dp[i - 1][j + 1] * j % md) %= md;
} else {
(dp[i][j] += dp[i - 1][j - 1]) %= md;
(dp[i][j] += dp[i - 1][j]) %= md;
}
}
}
}
cout << dp[N][1] << endl;
}
/*
1 36275 4
3 1 2
yeni component
elementi kimese birlesdirirsen
ya da iki componenti merge edirsen
*/
# | 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... |