Problem Solution of [NOIP Simulated Test 9] (Combination Number of Buckets + dp)

Keywords: C

I don't want any of Dagger's handouts. I feel like I'm a real bull.

$type=0:$

Similar to the visit question, the direct formula for enumerating the steps of lateral movement is derived.

$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 we can't touch the negative half-axis, we can think of the right shift as + 1, and the left shift as - 1, which can be transformed into the problem of prefix and greater than or equal to 0.

So just a direct Catalan number. Note that Catalan is the first $ frac {n}{2}$item.

$Catalan_n=C_{2n}^{n}-C_{2n}^{n-1}$

$type=2:$

It was observed that the data range was small and dp was considered.

Set $f[i] $as the number of scenarios that go back to the origin in step i, and transfer it by enumerating the number of steps j that go back to the origin for the first time.

Obviously, j can only be an even number.

$f[i]=\sum f[i-j]*Catalan(\frac{j}{2}-1)$

$type=3:$

Or to enumerate the number of lateral steps, combined with the Catalan number to solve.

$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;
}

Posted by sdlyr8 on Tue, 30 Jul 2019 14:45:31 -0700