#include <bits/stdc++.h>
#define ll long long
#define vec vector
#define pb push_back
#define pll array<ll, 2>
#define all(X) X.begin(), X.end()
#define allr(X) X.rbegin(), X.rend()
using namespace std;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
void _(){
ll n, cs,cf; cin >> n >> cs >> cf;
vec<vec<ll>>dp(n + 1, vec<ll>(n + 1, 0));
dp[1][1] = 1; ll fx = 0;
for(ll i = 1; i <= n; i++){
if(i == cs or i == cf) fx++;
for(ll j = 1; j <= i; j++){
if(i == cs or i == cf){
(dp[i][j + 1] += dp[i - 1][j]) %= mod;
(dp[i][j] += dp[i - 1][j]) %= mod;
}
else{
dp[i][j + 1] += (j + 1 - fx) * dp[i - 1][j];
dp[i][j - 1] += (j - 1) * dp[i - 1][j];
}
}
} cout << dp[n][1] << endl;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(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... |