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 <iostream>
#define MAXN 2010
#define MOD 1000000007
using namespace std;
long long dp[MAXN][MAXN];
int main() {
ios::sync_with_stdio(false); cin.tie(0);
long long n, cs, cf;
cin >> n >> cs >> cf;
dp[1][1] = 1;
for (int i = 2; i <= n; i++) {
for (long long j = 1; j <= i; j++) {
if (i == cs || i == cf) {
dp[i][j] = dp[i-1][j-1] + dp[i-1][j];
if (dp[i][j] >= MOD) dp[i][j] %= MOD;
} else {
dp[i][j] = j * dp[i-1][j+1];
dp[i][j] += (j+1 - (cs < i) - (cf < i)) * dp[i-1][j-1];
if (dp[i][j] >= MOD) dp[i][j] %= MOD;
}
}
}
cout << dp[n][1];
return 0;
}
# | 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... |