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 = 2000;
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)
kangaroo.cpp: In function 'int main()':
kangaroo.cpp:59:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
59 | scanf("%d%d%d", &N, &S, &E); if(S>E) swap(S, E);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# | 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... |