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;
int main() {
constexpr int64_t MOD = 1000000007;
int64_t n, cs, cf, fixed = 0;
cin >> n >> cs >> cf;
vector<vector<int64_t>> dp(n + 3, vector<int64_t>(n + 3, 0));
dp[1][1] = 1;
for (int64_t i = 1; i <= n; i++) {
if (i == cs or i == cf) {
fixed++;
}
for (int64_t j = 1; j < i; j++) {
if (i == cs or i == cf) {
dp[i][j] += dp[i - 1][j];
dp[i][j + 1] += dp[i - 1][j];
dp[i][j] %= MOD;
dp[i][j + 1] %= MOD;
continue;
}
dp[i][j - 1] += dp[i - 1][j] * (j - 1);
dp[i][j + 1] += dp[i - 1][j] * (j + 1 - fixed);
dp[i][j - 1] %= MOD;
dp[i][j + 1] %= MOD;
}
}
cout << dp[n][1] % MOD << '\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... |