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>
using namespace std;
const long long mod = 1e9+7;
long long n, st, ed, dp[2010][2010][3];
int main() {
cin >> n >> st >> ed;
if ((st == 1) || (ed == 1)) dp[1][1][1] = 1;
else dp[1][1][0] = 1;
for (int i = 2; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 0; k < 3; k++) {
if ((i == st) || (i == ed)) {
if (k > 0) {
if ((k < 2) || (i == n) || (j > 1)) (dp[i][j][k] += dp[i-1][j][k-1]) %= mod;
(dp[i][j][k] += dp[i-1][j-1][k-1]) %= mod;
}
} else {
(dp[i][j][k] += dp[i-1][j-1][k]*((j-1)*2-k)) %= mod;
(dp[i][j][k] += dp[i-1][j+1][k]*j) %= mod;
}
}
}
}
cout << dp[n][1][2] << endl;
}
# | 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... |