This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* author: longvu
* created: 10/06/22 10:25:38
**/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
const int INF = numeric_limits<int>::max();
const int nax = (int)(2901);
const int mod = 1e9 + 7;
template<class X, class Y>
bool maximize(X& x, const Y y) {
if (y > x) {x = y; return true;}
return false;
}
template<class X, class Y>
bool minimize(X& x, const Y y) {
if (y < x) {x = y; return true;}
return false;
}
int dp[nax][nax];
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, st, ed;
cin >> n >> st >> ed;
dp[0][0] = 1;
for (int i = 0; i < n; ++i) {
for (int j = 0; j <= n; ++j) {
if (i + 1 == st || i + 1 == ed) {
(dp[i + 1][j + 1] += dp[i][j]) %= mod;
if (j) {
(dp[i + 1][j] += dp[i][j]) %= mod;
}
continue;
}
if (j) {
(dp[i + 1][j - 1] += (j - 1) * dp[i][j] % mod) %= mod;
}
(dp[i + 1][j + 1] += (j + 1 - (i + 1 >= st) - (i + 1 >= ed)) * dp[i][j] % mod) %= mod;
}
}
cout << dp[n][1] << '\n';
return 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... |