#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define yes cout << "Yes" << "\n"
#define no cout << "No" << "\n"
#define pb push_back
#define F first
#define S second
#define int long long
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <ll, ll> pii;
typedef vector <pii> vii;
typedef vector <ll> vi;
template<typename T>
void read(vector<T>& v) {
for (auto &x : v) cin >> x;
}
template<typename T>
void print(const vector<T>& v) {
for (auto &x : v) cout << x << ' ';
cout << "\n";
}
const ll MAX = 2000 + 5;
const ll MOD = 1e9 + 7;
int dp[MAX][MAX];
int dp1[MAX][MAX];
void solve() {
int n, s, f;
cin >> n >> s >> f;
for (int i = 1; i <= n; i++) {
if (i == 1) {
dp[i][s] = 1;
dp1[i][s] = 1;
continue;
}
int cem = 0;
int say = 0;
for (int j = 1; j <= n; j++) {
if (j != s && (j != f || i == n)) {
dp[i][j] = (cem + MOD - dp[i - 2][j] * say % MOD) % MOD;
dp[i][j] = dp[i][j] % MOD;
}
cem += dp1[i - 1][j] % MOD;
cem = cem % MOD;
if (dp1[i - 1][j] > 0) {
say++;
}
}
cem = 0;
say = 0;
for (int j = n; j >= 1; j--) {
if (j != s && (j != f || i == n)) {
dp1[i][j] = (cem + MOD - (dp1[i - 2][j] * say) % MOD) % MOD;
dp1[i][j] = dp1[i][j] % MOD;
}
cem += dp[i - 1][j] % MOD;
cem = cem % MOD;
if (dp[i - 1][j] > 0) {
say++;
}
}
}
cout << dp1[n][f] + dp[n][f] << '\n';
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
//cin >> t;
for (int i = 1; i <= t; i++) {
solve();
}
}
| # | 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... |