2018 Changsha University of Science and Technology 13th Programming Competition J Cup (Cattleland Number)

Click to open the link


Parse:

This is actually an order of popping and pushing into the stack. After asking you the mth push, the ball in the stack has a digit k.

Click to open the link for a detailed explanation of the Cattelan number . The key is to understand the analysis of using binary numbers to explain the order of entry and exit of the stack represented by the Cattelan number.

We take '1' as push and '0' as stack

In this way, it is actually converted into after the mth 1 is put in,

There are (excluding the mth 1, because its position is fixed) m-1 1s, mk 0s, let you arrange how many legal situations
there are After entering, there are k balls immediately, so the position of the mth 1 is actually fixed, it must be at the 2m-kth position

This becomes the case of the ordinary Cattelan number: (total situation - illegal situation (the accumulated number of 0 before the accumulated number > 1 at a certain moment, that is, there is no element in the stack and it continues to pop up))
there must be an odd number 2w When +1 bit, there are w 1s in front, w+1 0s, then we swap the 0s and 1s of all the bits after this bit, then

1: m-1 (total) w (first 2w+1 bits) m-1-w (last 2m-k-1-2w-1 bits) -> mk-1 (after transformation)
0: mk (Total) w+1 (first 2w+1 bits) mkw-1 (last 2m-k-1-2w-1 bits) -> m (after transformation)
so the illegal case is C(2m-k-1 ,m)
, then the case of the former part is p1=C(2m-k-1,m-1)-C(2m-k-1,m)

The same is true for the latter part (note that at the beginning, there are already k bits in the stack, so the first illegal occurrence is 2w+k+1 ​​bits)
1: nm (total) w (the first 2w+ k+1 bits) nmw (last 2n-2w-1 bits) -> nm-1 (after transformation)
0: n-m+k (total) w+k+1 ​​(first 2w+k+1 ​​bits) ) nmw-1 (last 2n-2w-1 bits) ->n-m+k+1 (after transformation) , then the illegal case of the latter part is the case
of the latter part of C(2n-2m+k, nm-1)
is p2=C(2n-2m+k,nm)-C(2n-2m+k,nm-1)
years=p1*p2

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define INF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007

typedef long long int lli;
const int MAXN = 2e6+20;
lli jc [MAXN];


flax pow (flax a, flax n, flax p)
{
    years = 1;
    while(n){
        if(n&1) ans=ans*a%p;
        n=n>>1;
        a=a*a%p;
    }
    return ans%p;
}

linen niYuan (linen a, linen b)
{
    return pow(a,b-2,b);
}

flax C (flax a, flax b)
{
    return jc [a] * niYuan (jc [b], MOD)% MOD * niYuan (jc [ab], MOD)% MOD;
}

void caljc()
{
    lli p = 1;
    jc[0]=1;
    for(int i=1;i<MAXN;i++)
    {
        p=(p*i)%MOD;
        jc[i]=p;
    }
}


intmain()
{
    int t;
    caljc();
    scanf("%d",&t);
    while(t--)
    {
        lli n, m, k;
        scanf("%lld%lld%lld",&n,&m,&k);
        if(m>n||k>m)
        {
            printf("0\n");
            continue;
        }
        linen part1;
        if(m==k) part1=1;
        else part1=(C(2*m-k-1,m-1)-C(2*m-k-1,m)+MOD)%MOD;
        linen part2;
        if(m==n) part2=1;
        else part2=(C(2*n-2*m+k,n-m)-C(2*n-2*m+k,n-m-1)+MOD)%MOD;
        printf("%lld\n",part1*part2%MOD);

    }
    return 0;

}




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324473788&siteId=291194637