#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9 + 7, maxn = 2e3 + 5;
int dp[maxn][maxn];
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n, s, e; cin >> n >> s >> e;
dp[1][1] = 1;
//xét tới i, tạo j thành thành phần liên thông
for (int i = 2; i <= n; i++){
if(i != s && i != e){
//merge 2 thành phần liên thông lại, hoặc tạo thêm một thành phần liên thông mới
for(int j = 1; j <= n; j++) dp[i][j] = (dp[i - 1][j + 1] * j + dp[i - 1][j - 1] * (j - (i > s) - (i > e))) % mod;
}
else{
//tạo tplt mới ở vị trí cần thiết, hoặc đặt vào tplt đầu/cuối đang có
for(int j = 1; j <= n; j++) dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j]) % mod;
}
}
cout << dp[n][1] % mod;
}
# | 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... |