# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
308920 | arnold518 | 캥거루 (CEOI16_kangaroo) | C++14 | 2 ms | 1664 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;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 400;
const ll MOD = 1e9+7;
int N, S, E;
ll dp[MAXN+10][MAXN+10];
ll solve(int pos, int comp)
{
if(pos==N+1)
{
if(comp==1) return 1;
else return 0;
}
ll &ret=dp[pos][comp];
if(ret!=-1) return ret;
ret=0;
if(pos==S)
{
ret+=solve(pos+1, comp);
ret+=solve(pos+1, comp+1);
}
else if(pos==E)
{
ret+=solve(pos+1, comp);
ret+=solve(pos+1, comp+1);
}
else if(pos<S)
{
if(comp>=2) ret+=(comp-1)*solve(pos+1, comp-1);
ret+=(comp+1)*solve(pos+1, comp+1);
}
else if(pos<E)
{
if(comp>=2) ret+=(comp-1)*solve(pos+1, comp-1);
ret+=(comp)*solve(pos+1, comp+1);
}
else
{
if(comp>=2) ret+=(comp-1)*solve(pos+1, comp-1);
ret+=(comp-1)*solve(pos+1, comp+1);
}
ret%=MOD;
//printf("%d %d : %lld\n", pos, comp, ret);
return ret;
}
int main()
{
scanf("%d%d%d", &N, &S, &E); if(S>E) swap(S, E);
memset(dp, -1, sizeof(dp));
printf("%lld\n", solve(1, 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... |