This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// author - alimammadzade
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
cin.tie(nullptr)->sync_with_stdio(0);
// system("cls"), freopen("in.txt", "r", stdin);
int n, s, f, fixed = 0, mod = 1e9 + 7;
cin >> n >> s >> f;
vector<vector<int>> dp(n + 1, vector<int>(n + 1));
dp[1][1] = 1;
for (int i = 1; i <= n; i++) {
fixed += (i == s or i == f);
for (int j = 1; j < i; j++)
if (i == s or i == f) {
(dp[i][j + 1] += dp[i - 1][j]) %= mod;
(dp[i][j] += dp[i - 1][j]) %= mod;
}
else {
(dp[i][j + 1] += (j + 1 - fixed) * dp[i - 1][j]) %= mod;
(dp[i][j - 1] += (j - 1) * dp[i - 1][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... |