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
const int N = 2e3 + 5;
const int mod = 1e9 + 7;
void add(int &a, int b) {
a += b;
if(a >= mod) a -= mod;
if(a < 0) a += mod;
}
int n, sta, fin;
int dp[N][N];
void solve() {
cin >> n >> sta >> fin;
dp[0][0] = 1;
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= i; ++j) {
if(i == sta || i == fin) {
add(dp[i][j], (dp[i - 1][j - 1] + dp[i - 1][j]) % mod);
}
else {
int res = j - (i > sta) - (i > fin);
add(dp[i][j], (1ll * dp[i - 1][j - 1] * res + 1ll * j * dp[i - 1][j + 1]) % mod);
}
}
}
cout << dp[n][1] << '\n';
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int test = 1;
// cin >> test;
while(test--) solve();
return 0;
}
// https://oj.uz/problem/view/CEOI16_kangaroo
# | 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... |