#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--)
#define pa pair<ll, ll>
#define fi first
#define se second
#define bit(mask, j) ((mask >> j) & 1)
const ll mod = 1e9 + 7;
const ll INF = 1e18;
//--------------------------------------------------------------------
ll s, t;
ll n;
const ll N = 2003;
ll f[N][N][3];
ll calc(ll i, ll j, ll c) {
if(i == n + 1) return j == 1;
ll res = 0;
if(f[i][j][c] != -1) return f[i][j][c];
if(i == s || i == t) {
if(j != 0)
res += calc(i + 1, j, c + 1);
res += calc(i + 1, j + 1, c + 1);
}
else {
res += calc(i + 1, j + 1, c) * (j + 1 - c);
if(j >= 2)
res += calc(i + 1, j - 1, c) * (j - 1);
}
return f[i][j][c] = res;
}
void hbmt() {
memset(f, -1, sizeof f);
cin >> n >> s >> t;
cout << calc(1, 0, 0);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
#define NAME "hbmt"
if(fopen(NAME".inp", "r")) {
freopen(NAME".inp", "r", stdin);
freopen(NAME".out", "w", stdout);
}
//int t;cin>>t;while(t--)
hbmt();
return 0;
}
Compilation message (stderr)
kangaroo.cpp: In function 'int main()':
kangaroo.cpp:47:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | freopen(NAME".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
kangaroo.cpp:48:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
48 | freopen(NAME".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~| # | 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... |