# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
472000 | DEQK | Kangaroo (CEOI16_kangaroo) | C++17 | 27 ms | 14252 KiB |
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;
const int N = 2020;
const int mod = 1e9 + 7;
int n, a, b;
int dp[N][N];
void inc(int &x,int y) {
x += y;
if(x >= mod) x -= mod;
}
int main() {
scanf("%d%d%d", &n, &a, &b);
dp[1][1] = 1;
for(int i = 1; i < n; i++) {
for(int j = 1; j <= i; j++) {
if(dp[i][j] == 0) continue; // doesnt contribute to answer
if(i + 1 == a || i + 1 == b) {
inc(dp[i + 1][j], dp[i][j]);
inc(dp[i + 1][j + 1], dp[i][j]);
} else {
inc(dp[i + 1][j - 1], dp[i][j] * 1ll * (j - 1) % mod);
inc(dp[i + 1][j + 1], dp[i][j] * 1ll * (j + 1 - (i + 1 > a) - (i + 1 > b)) % mod); // can not be to the left a and to the right b
}
}
}
printf("%d", dp[n][1]);
}
Compilation message (stderr)
# | 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... |