This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define nl "\n"
#define nf endl
#define ll long long
#define pb push_back
#define _ << ' ' <<
#define INF (ll)1e18
#define mod 1000000007
#define maxn 2010
ll i, i1, j, k, k1, t, n, m, res, flag[10], a, b;
ll st, nd, dp[maxn][maxn];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
#if !ONLINE_JUDGE && !EVAL
ifstream cin("input.txt");
ofstream cout("output.txt");
#endif
cin >> n >> st >> nd;
if (n == 2) {
cout << 1 << nl; return 0;
}
dp[1][1] = 1;
for (i = 1; i <= n; i++) {
if (i == st || i == nd) k++;
if (i == 1) continue;
for (j = 0; j <= n; j++) {
if (i == st || i == nd) {
if (j >= 1) dp[i][j] += dp[i - 1][j - 1];
if (st + nd != 3) dp[i][j] += dp[i - 1][j];
} else {
if (j >= 1) dp[i][j] += (max((ll)0, j - k) * dp[i - 1][j - 1]);
dp[i][j] += (j * dp[i - 1][j + 1]);
}
dp[i][j] %= mod;
}
}
/* for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
cout << dp[i][j] << ' ';
}
cout << nl;
} */
cout << dp[n][1] << nl;
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... |