Bzoj 1856 [Scoi2010] string combination number

Source: Internet
Author: User

Test Instructions:
Find a string consisting of n 1,m 0, and the number of 1 in any preceding characters cannot be less than 0, ask for the number of strings that satisfy the requirement.
parsing:
It's easy to convert the test instructions to the number of schemes that go from the left down of a matrix to the right and not over a line.
If we think of 1 as a vector (0) and a vector (1,-1), then we can turn the model into a scheme that goes from (0,0) to (N+M,N-M) and does not go straight y=-1.
Without considering limiting the answer is obviously C (n+m,m), if the restriction is considered, we see that the y=-1 situation can be seen as the number of scenarios from (0,-2) to (N+M,N-M).

So the number of illegal programs is exactly C (n+m,m-1) (originally can choose M 0, but now because the ordinate down 2, so have to walk a 0, more than a 1 to convert into m-1, of course, can also be seen as (n+m-(n-m+2)) >>1)
Code:

#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define MOD 20100403#define N 2001000Using namespace Std;typedef long long ll;intNm; ll fac[n];void Init () {fac[0]=1; for(intI=1; i<=2000000; i++) fac[i]=fac[i-1]*(LL) I%mod;} ll Get_inv (LLx, LLy) {ll ret=1; while(y)    {if(y&1) ret= (ret*x)%mod;x=(x*x)%mod;y>>=1; }returnRET;} ll Get_c (LL N,llm){returnFac[n]*GET_INV(fac[m],mod-2)%mod*GET_INV(fac[n-m],mod-2)%mod;}intMain () {init (); scanf"%d%d",&n,&m);printf("%lld\ n", ((Get_c (n+m,m)-get_c (n+m,m-1)%mod+MOD)%mod));}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Bzoj 1856 [Scoi2010] string combination number

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.