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;
const int N = 2020;
const int mod = 1000000007;
int f[N][N];
void add(int &x, int y) {
x += y; if (x >= mod) x -= mod;
}
int mul(int x, int y) {
return (long long) x * y % mod;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
int n, cs, cf;
cin >> n >> cs >> cf;
f[1][1] = 1;
for (int i = 2; i <= n; ++i) {
for (int j = 1; j < i; ++j) {
if (i == cs || i == cf) {
add(f[i][j], f[i - 1][j]);
add(f[i][j + 1], f[i - 1][j]);
} else {
if (j >= 2) add(f[i][j - 1], mul(f[i - 1][j], j - 1));
int k = j - (i > cs) - (i > cf) + 1;
add(f[i][j + 1], mul(f[i - 1][j], k));
}
}
}
cout << f[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... |