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