# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
44782 | bogdan10bos | Kangaroo (CEOI16_kangaroo) | C++14 | 24 ms | 14464 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;
//#define FILE_IO
const int mod = 1e9 + 7;
int dp[2005][2005];
int main()
{
#ifdef FILE_IO
freopen("1.in", "r", stdin);
freopen("1.out", "w", stdout);
#endif
int N, st, fn;
scanf("%d%d%d", &N, &st, &fn);
dp[1][1] = 1;
int ends = 2;
if(st == 1 || fn == 1) ends--;
for(int i = 2; i <= N; i++)
{
if(i == st || i == fn)
{
for(int j = 1; j <= i; j++)
dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1]) % mod;
ends--;
continue;
}
for(int j = 1; j <= i; j++)
{
dp[i][j] = 0;
if(j - 2 + ends >= 0)
dp[i][j] = (1LL * dp[i - 1][j - 1] * (j - 2 + ends)) % mod;
dp[i][j] += (1LL * dp[i - 1][j + 1] * j) % mod;
dp[i][j] %= mod;
}
}
printf("%d\n", dp[N][1]);
return 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... |