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;
using ll = long long;
using pl = pair<ll, ll>;
#define vt vector
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define F0R(i, b) FOR (i, 0, b)
#define endl '\n'
#define debug(x) do{auto _x = x; cerr << #x << " = " << _x << endl;} while(0)
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
void add(ll& a, ll b) {
a = (a + (b % MOD)) % MOD;
}
main() {
cin.tie(0)->sync_with_stdio(0);
int n, st, en; cin >> n >> st >> en;
vt dp(n + 1, vt<ll>(n + 2));
dp[1][1] = 1;
FOR (i, 2, n + 1) {
FOR (j, 1, n + 1) {
if (i == st || i == en) { // place either as a new component, or glue to some previous one
add(dp[i][j], dp[i - 1][j - 1] + dp[i - 1][j]);
} else { // place either as a new component, or glue together two previous ones
add(dp[i][j], dp[i - 1][j - 1] * (j - (i > st) - (i > en)) + dp[i - 1][j + 1] * j);
}
}
}
cout << dp[n][1] << endl;
}
Compilation message (stderr)
kangaroo.cpp:25:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
25 | main() {
| ^~~~
# | 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... |