#include <bits/stdc++.h>
using namespace std;
long long dp[2001][2001];
int main() {
int n, cs, cf; cin >> n >> cs >> cf;
for (int i = 0; i <= n;i++) for (int j = 0; j <= n; j++) dp[i][j] = 0;
dp[1][1] = 1;
for (int i = 2; i <= n; i++) {
for (int j = 1; j <= i; j++) {
if (i == cs || i == cf) {
dp[i][j] = (dp[i-1][j-1] + dp[i-1][j])%1000000007;
} else {
int j2 = j-(i>cs)-(i>cf);
dp[i][j] = (dp[i-1][j-1] + dp[i-1][j+1]*((j2+1)*j2%1000000007))%1000000007;
// dp[i][j] = dp[i-1][j+1]*j + dp[i-1][j-1]*(j-(i>cs)-(i>cf));
}
}
}
//cout << dp[n][1] << endl;
cout << dp[n][3] << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |