#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using ll = long long;
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const double pi = acos(-1);
const int N = 2e3 + 5, K = 1e3 + 5, SQ = 500, M = 1e9 + 7;
//#define TESTS
//#define INTERACTIVE
//#define COMMUNICATION
/*
* Remember who you are.
*/
void pre() {
}
int dp[N][N], vis[N][N], vid, n, s, e;
int rec(int i, int j)
{
if (j < 0)
return 0;
if (i == n)
return j == 1;
auto &ret = dp[i][j], &v = vis[i][j];
if (v == vid)
return ret;
v = vid;
ret = 0;
if (s == i || e == i)
ret = rec(i + 1, j + 1) + rec(i + 1, j);
else
ret = 1ll * rec(i + 1, j + 1) * (j + 1 - (i > s) - (i > e)) % M
+
1ll * rec(i + 1, j - 1) * (j - 1) % M;
return ret %= M;
}
void solve() {
cin >> n >> s >> e;
s--, e--;
++vid;
cout << rec(0, 0);
}
void solve2() {
}
signed main() {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#ifdef CAROOT
#ifndef INTERACTIVE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
#else
#endif
int tt = 1;
pre();
#ifdef COMMUNICATION
string run;
cin >> run;
#endif
#ifdef TESTS
cin >> tt;
#endif
for (int tc = 1; tc <= tt; ++tc) {
#ifdef COMMUNICATION
if (run == "first")
solve();
else
solve2();
#else
solve();
#endif
cout << '\n';
}
}
| # | 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... |