#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
typedef pair<ll,ll> pii;
const int MAXN = 2e3+5, MOD = 1e9+7;
int N, S, T;
ll dp[MAXN][MAXN][3];
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> N >> S >> T;
dp[1][1][S==1||T==1] = 1;
for (int i=1;i<N;i++) {
for (int j=1;j<=i;j++) {
if (i+1==S || i+1==T) {
for (int k=0;k<2;k++) {
dp[i+1][j+1][k+1] = (dp[i+1][j+1][k+1] + dp[i][j][k]) % MOD;
dp[i+1][j][k+1] = (dp[i+1][j][k+1] + dp[i][j][k]) % MOD;
}
}
else {
for (int k=0;k<3;k++) {
dp[i+1][j+1][k] = (dp[i+1][j+1][k] + dp[i][j][k]*(j+1-k)) % MOD;
// dp[i+1][j][k] = (dp[i+1][j][k] + dp[i][j][k]*(2*j-k)) % MOD;
dp[i+1][j-1][k] = (dp[i+1][j-1][k] + dp[i][j][k]*(j-1)) % MOD;
}
}
}
}
cout << dp[N][1][2] << "\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... |