#include <bits/stdc++.h>
// #include "debug.h"
using namespace std;
using ll = long long;
using ld = long double;
const int N = 2e3 + 5 , M = 1e9 + 7;
int add(ll a , int b) {
return (a + b + M) % M;
}
int mul(ll a , int b) {
return a * b % M;
}
int dp[N][N] , st , en , n;
int solve(int i , int j) {
if (j < 0) return 0;
if (i == n)
return j == 1;
auto &ret = dp[i][j];
if (~ret)
return ret;
ret = 0;
// forced one position
if (i == st || i == en) {
ret = add(ret , solve(i + 1 , j));
ret = add(ret , solve(i + 1 , j + 1));
} else {
// start a new comp
ret = add(ret , mul(j + 1 - (i > st) - (i > en) , solve(i + 1 , j + 1)));
if (j >= 2) // merge two comps
ret = add(ret , mul(j - 1 , solve(i + 1 , j - 1)));
}
return ret;
}
void solve() {
cin >> n >> st >> en;
st-- , en--;
cout << solve(0 , 0);
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
memset(dp, -1, sizeof dp);
int tc = 1;
// cin >> tc;
while (tc--) solve();
}
| # | 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... |