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;
typedef long long ll;
const int MOD = 1e9+7;
const int MAXN = 2001;
int dp[MAXN][MAXN];
int n, a, b;
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> n >> a >> b;
a--; b--;
dp[0][0] = 1;
for (int i = 0; i < n; i++) {
for (int j = 1; j <= min(i+1, n-i); j++) {
if (i == a || i == b) {
dp[i+1][j] = dp[i][j]+dp[i][j-1];
dp[i+1][j] %= MOD;
}
else {
dp[i+1][j] = ((ll) (j-(i >= a)-(i >= b))*dp[i][j-1]+(ll)j*dp[i][j+1]) % MOD;
}
}
}
cout << dp[n][1] << "\n";
}
# | 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... |