This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N_MAX = 2000;
const int MOD = (int) 1e9 + 7;
int N, L, R;
int dp[N_MAX + 2][N_MAX + 2];
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> N >> L >> R;
dp[0][1] = 1;
for (int i = 1; i <= N; i++) {
for (int open = 0; open <= N; open++) {
if (i == L || i == R) {
dp[i][open] += dp[i - 1][open];
if (dp[i][open] >= MOD) {
dp[i][open] -= MOD;
}
dp[i][open - 1] += dp[i - 1][open];
if (dp[i][open - 1] >= MOD) {
dp[i][open - 1] -= MOD;
}
} else {
dp[i][open + 1] = (dp[i][open + 1] + (ll) dp[i - 1][open] * open) % MOD;
dp[i][open - 1] = (dp[i][open - 1] + (ll) dp[i - 1][open] * max(0, open - (i < L) - (i < R))) % MOD;
}
}
}
cout << dp[N][0] << "\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... |