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;
typedef long long ll;
const int mod = 1e9 + 7;
int32_t main () {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int N, cs, cf;
cin >> N >> cs >> cf;
vector<vector<ll>> dp(N + 1, vector<ll>(N + 1, 0));
dp[0][0] = 1;
int say = 0;
for (int i = 0;i < N;i ++) {
for (int j = 0;j <= i;j ++) {
if (i + 1 == cs || i + 1 == cf) {
say ++;
dp[i + 1][j + 1] = (dp[i][j] + dp[i + 1][j + 1]) % mod;
dp[i + 1][j] = (dp[i][j] + dp[i + 1][j]) % mod;
} else {
dp[i + 1][j + 1] = (dp[i][j] * (j + 1 - say) + dp[i + 1][j + 1]) % mod;
if (j - 1 >= 0) dp[i + 1][j - 1] = (dp[i][j] * (j - 1) + dp[i + 1][j - 1]) % mod;
}
}
}
// for (int i = 1;i <= N;i ++) {
// for (int j = 1;j <= i;j ++) {
// // for (int k = 0;k < 3;k ++) {
// cout << dp[i][j] << " ";
// // } cout << "\n";
// } cout << "\n";
// } cout << "\n";
cout << 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... |