20181009noip HZ EZ Two-school joint test sum (Mo Team, combinatorial mathematics)

Source: Internet
Author: User

Face stamp Here

Idea: Noip team??!!!

The examination room is dead or alive not to this aspect to think AH!!! Data divide forget write endl50pts roll thick

Every query here has n,m two parameters

We can think of it as the L and R in the regular team.

Then we can use the recursive nature of the combined number.

Believe in Change m everyone will write, n?

Look at the picture:

We found that $S _n^m = s_{n-1}^m \times 2-c_n^{m+1} + c_{n-1}^{m+1}$

(Because of the nature of the Yang Hui triangle)

So n can also be recursive

Just set up a MO team.

Code:
#include <iostream>#include<cstdio>#include<algorithm>#defineRii Register int i#defineRij Register Int J#defineint long LongConst intp=1e9+7;using namespacestd;structque{intN,M,ANS,BH;} x[100005];intny[100005],jc[100005],jcny[100005],q,sy[100005],nn,nm,ans;voidQny () {ny[1]=1; ny[0]=1;  for(rii=2; i<=100000; i++) {Ny[i]= (p-p/i) *ny[p%i]%p; }}voidJic () {jcny[0]=1; jc[1]=1; jcny[1]=1;  for(rii=2; i<=100000; i++) {Jc[i]=jc[i-1]*i; Jc[i]%=p; Jcny[i]=jcny[i-1]*Ny[i]; Jcny[i]%=p; }}voidYcl () {qny (); JIC ();}BOOLcmp1 (que lk,que KL) {if(sy[lk.n]==SY[KL.N]) {        returnlk.m<kl.m; }    returnlk.n<KL.N;}BOOLcmp2 (que lk,que KL) {returnlk.bh<kl.bh;}intCintNintm) {    intkkk=Jcny[m]; KKK*=Jc[n]; KKK%=p; KKK*=jcny[n-m]; KKK%=p; returnKKK;}voidcnintZL) {    if(zl==1) {ans*=2; Ans-=c (nn+1, nm+1); Ans+=c (nn,nm+1); Ans+=p; Ans%=p; }    if(zl==-1) {ans+=c (nn,nm+1); Ans-=c (nn-1, nm+1); Ans+=p; Ans%=p; Ans*=ny[2]; Ans%=p; }}voidcmintZL) {    if(zl==1) {ans+=c (nn,nm+1); }    Else{ans-=c (NN,NM); Ans+=p; } ans%=p;} Signed Main () {Freopen ("sum.in","R", stdin); Freopen ("Sum.out","W", stdout);    YCL (); scanf ("%lld",&q); scanf ("%lld",&q); intlen= the;  for(rii=1; i<=100000; i++) {Sy[i]=i/len+1; }     for(rii=1; i<=q;i++) {scanf ("%lld%lld",&x[i].n,&x[i].m); X[I].BH=i; } sort (x+1, x+q+1, CMP1); NN=1, nm=0, ans=1;  for(rii=1; i<=q;i++)    {        if(x[i].m<nn) {             while(nm>x[i].m) {cm (-1); NM--; }             while(nm<x[i].m) {cm (1); NM++; }             while(nn<X[I].N) {cn (1); NN++; }             while(nn>X[I].N) {cn (-1); NN--; }        }         while(nn<X[I].N) {cn (1); NN++; }         while(nn>X[I].N) {cn (-1); NN--; }         while(nm>x[i].m) {cm (-1); NM--; }         while(nm<x[i].m) {cm (1); NM++; } X[i].ans=ans; } sort (x+1, x+q+1, CMP2);  for(rii=1; i<=q;i++) {printf ("%lld\n", X[i].ans); }}

20181009noip HZ EZ Two-school joint test sum (Mo Team, combinatorial mathematics)

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.