Dage send points to me I do not, feel very cattle batch.
$type=0:$
That question is similar with the visit, a few steps enumerate the lateral movement of the push formulas directly:
$ans=\sum C_n^i \times C_i^{\frac{i}{2}} \times C_{n-i}^{\frac{n-i}{2}},i%2=0$
$type=1:$
Because they can not touch the negative axle, the right can be seen the +1, -1 as the left, into the prefix and greater than or equal to 0 problems
So the number of direct Catalan enough. Note that the first Catalan is $ \ frac {n} {2} $ item.
$Catalan_n=C_{2n}^{n}-C_{2n}^{n-1}$
$type=2:$
Observed data is small, to consider dp.
Set $ f [i] $ is the number of i-step plan to go back to square one, the first time back to square one by enumerating the number of steps j transferred.
Obviously j can only be an even number.
$f[i]=\sum f[i-j]*Catalan(\frac{j}{2}-1)$
$type=3:$
Or enumerate a few steps away laterally, combined with the number of Catalan solved.
$ans=\sum C_n^i*Catalan(\frac{i}{2})*Catalan(\frac{n-i}{2})$
#include<cstdio> #include<iostream> #include<cstring> using namespace std; typedef long long ll; const ll mod=1000000007; const int N=100005; int n,op; ll fac[N<<1],ans,dp[N<<1]; ll qpow(ll a,ll b) { ll res=1;//a%=mod; while(b) { if(b&1)res=res*a%mod; a=a*a%mod; b>>=1; } return res; } ll ini() { fac[0]=1; for(int i=1;i<=(N-5)<<1;i++) fac[i]=1LL*i*fac[i-1]%mod; } ll C(ll x,ll y) { if(y>x)return 0; return fac[x]*qpow(fac[y],mod-2)%mod*qpow(fac[x-y],mod-2)%mod; } ll lucas(ll x,ll y) { if(!y)return 1; return C(x%mod,y%mod)*lucas(x/mod,y/mod)%mod; } ll Catalan(ll x) { return (lucas(x*2,x)-lucas(x*2,x-1)+mod)%mod; } void qj1() { //cout<<2*n<<endl; //cout<<C(2*n,n)<<endl; ans=Catalan(1LL*n/2); cout<<ans<<endl; } void qj0() { for(int i=0;i<=n;i++) { if(i%2)continue; ans+=lucas(1LL*n,1LL*i)%mod*lucas(1LL*i,1LL*i/2)%mod*lucas(1LL*(n-i),1LL*(n-i)/2)%mod,ans%=mod; } cout<<ans<<endl; } void qj3() { for(int i=0;i<=n;i++) { if(i%2)continue; ans+=lucas(1LL*n,1LL*i)*Catalan(1LL*i/2)%mod*Catalan(1LL*(n-i)/2)%mod,ans%=mod; } cout<<ans<<endl; } void qj2() { dp[0]=1; for(int i=2;i<=n;i+=2) for(int j=2;j<=i;j+=2) dp[i]+=dp[i-j]*4%mod*Catalan(1LL*j/2-1LL)%mod,dp[i]%=mod; cout<<dp[n]<<endl; } int main() { scanf("%d%d",&n,&op); ini(); if(op==1)qj1(); else if(op==0)qj0(); else if(op==3)qj3(); else qj2(); return 0; }