[SCOI2010] generated strings (combinations count)

[SCOI2010] generated string (luogu)

Description

Title Description

lxhgww recently received a task generated string of n tasks he needs a string composed of 0 and m,

But the task requested in the string consisting of, any first k characters, the number of not less than 1, the number of zeros.

Now lxhgww you want to know to meet the requirements of the total number of strings, clever programmers, can you help him?

Input Format

The input data is a line, comprising two numbers n and m

Output Format

The output data is a line, comprising a number representing the number of the string to meet the requirements, this number may be very large,

Just this number is divided by the output of 20,100,403

Solution

Establishing plane rectangular coordinate system, provided the starting point (the empty string) coordinates (0, 0),

At the end of addition of a 1 + 1 as the abscissa, ordinate +1

Increase at the end of a 1 + 1 as the abscissa, ordinate -1

Terminating point (n + m, nm)

Reaches the end point of the program number (prefix is ​​not considered to limit the number 1) = $ C ^ m_ {n + m} $

Figure borrow Gangster

Title does not satisfy the limitation found when passing this straight line y = -1

(0,0) = y to a point equal to the program number (0, -2) to a point on the y -1 = the number of programs -1

Thus the number of the program does not satisfy the restriction condition program number (0, -2) to the ending point = $ C ^ {m-1} _ {n + m} $

Answer is $ C ^ m_ {n + m} -C ^ {m-1} _ {n + m} $

 

Code

 

#include <cstdio>
#include <cstdlib>
#define ll long long
using namespace std;
const int N=2e6+10;
const ll P=20100403;
ll d[N],ans;
int n,m;
ll qpow(ll x,ll y)
{
    ll an=1;
    while(y)
    {
        if(y&1) ans=ans*x%P;
        x=x*x%P,y>>=1;
    }
    return an;
}
int main()
{
    scanf("%d%d",&n,&m);

    d[0]=1;
    for(ll i=1;i<=n+m;i++)
        d[i]=d[i-1]*i%P;
    ans=(n+1-m)*d[n+m]%P;
    ans=ans*qpow(d[n+1],P-2)%P;
    ans=ans*qpow(d[m],P-2)%P;
    printf("%lld\n",ans);
    return 0;
}

 

 

 

 

Guess you like

Origin www.cnblogs.com/hsez-cyx/p/12407361.html