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;
#define SPEED ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define ALL(x) x.begin(), x.end()
#define intt long long
#define pb push_back
#define endl "\n"
const int mod = 1e9 + 7, inf = 1e9;
void solve() {
intt n, cs, cf;
cin >> n >> cs >> cf;
vector<vector<intt>> dp(n + 1, vector<intt>(n + 1));
dp[1][1] = 1;
intt fixed = 0;
for(int i = 1; i <= n; i++) {
fixed += (i == cs || i == cf);
for(int j = 1; j < i; j++) {
if(i == cs || i == cf) {
dp[i][j+1] += (dp[i-1][j]);
dp[i][j+1] %= mod;
dp[i][j] += (dp[i-1][j]);
dp[i][j] %= mod;
} else {
dp[i][j+1] += (dp[i-1][j] * (j + 1 - fixed));
dp[i][j+1] %= mod;
dp[i][j-1] += (dp[i-1][j] * (j - 1));
dp[i][j-1] %= mod;
}
}
}
cout << dp[n][1] << endl;
}
int main() {
SPEED;
intt tst = 1;
// cin >> tst;
while (tst--) {
solve();
}
}
# | 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... |