# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
59105 | gabrielsimoes | Kangaroo (CEOI16_kangaroo) | C++17 | 115 ms | 32340 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;
typedef long long ll;
const int MAXN = 2000;
const ll MOD = 1000000007;
int n, cs, cf;
ll dp[MAXN][MAXN];
ll f(int i, int k) {
if (k < 0) return 0;
if (i == n-1) return k == 0 ? 1 : 0;
ll &ret = dp[i][k];
if (ret != -1) return ret;
ret = 0;
ll ks = i > cs;
ll kf = i > cf;
if (i == cs || i == cf) {
ret += f(i+1, k);
ret += f(i+1, k-1) * k;
} else {
ret += f(i+1, k+1);
ret += f(i+1, k-1) * (k*(k-1) + ks*k + k*kf);
}
return ret %= MOD;
}
int main() {
memset(dp, -1, sizeof(dp));
scanf("%d %d %d", &n, &cs, &cf);
cs--;
cf--;
printf("%d\n", f(0, 0));
}
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... |