// dp[i][j] = the number of ways if consider the first i-th element and divide it into j
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#define INF 1e9
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
ll dp[2005][2005];
void solve()
{
int n, s, e; cin >> n >> s >> e;
dp[1][1] = 1;
for (int i = 2; i <= n; i++) {
if (i != s && i != e) {
for (int j = 1; j <= n; j++) dp[i][j] = (dp[i - 1][j + 1] * j + dp[i - 1][j - 1] * (j - (i > s) - (i > e))) % MOD;
}
else {
for (int j = 1; j <= n; j++) {
dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j]) % MOD;
}
}
}
cout << dp[n][1] % MOD << "\n";
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;// cin >> t;
while (t--) solve();
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... |