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 ll long long
#define pii pair<int, int>
#define ff first
#define ss second
#define pb push_back
#define rep(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define rep1(i, a, b) for (int i = (int)a; i >= (int)b; --i)
#define all(x) x.begin(), x.end()
const int N = 2e3 + 5;
const int mod = 1e9 + 7;
int dp[N][N];
int main() {
int n, a, b; cin >> n >> a >> b;
dp[1][1] = 1;
rep(i, 1, n - 1) rep(j, 1, n) {
if (i + 1 == a || i + 1 == b) {
(dp[i + 1][j] += dp[i][j]) %= mod;
(dp[i + 1][j + 1] += dp[i][j]) %= mod;
}
else {
// merge two components
(dp[i + 1][j - 1] += dp[i][j] * (j - 1)) %= mod;
// create a new component
(dp[i + 1][j + 1] += (dp[i][j] * (j + 1 - (i + 1 > a) - (i + 1 > b)))) %= mod;
}
}
cout << dp[n][1];
}
# | 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... |