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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, cs, cf; cin >> n >> cs >> cf;
const int MOD = 1e9 + 7;
long long dp[n+1][n+1] = {};
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
if (i == cs || i == cf) {
dp[i][j] = dp[i-1][j] + dp[i-1][j-1];
} else {
dp[i][j] = (
dp[i-1][j-1]*(j - (cs < i) - (cf < i)) +
dp[i-1][j+1]*j % MOD
) % 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... |