BZOJ4591[SHOI2015] super-energy particle cannon • change

Source: Internet
Author: User

BZOJ4591[SHOI2015] super-energy particle cannon • change

Test instructions

(Sigma (I,0,k) C (n,i))%2333. n,k≤1018

Exercises

According to the Lucas theorem (I will not), C (n,k)%2333=c (n/2333,k/2333) *c (n%2333,k%2333), it is possible to do some simplification (eliminate the mold)

(Sigma (I,0,k) C (n,i))=sigma (i,0,k) C (n/2333,i/2333) *c (n%2333,i%2333)

=Sigma (i,0,k/2333-1) C (n/2333,i)* (Sigma (j,0,2332) C (n%2333,j)) +C (n/2333,k/2333)*sigma (i,0,k% 2333) C (n%2333,i)

Start by handing out I,j≤2333 's c[i][j] and Sm[i][j] (for Sigma (K,0,J) c[i][k]), then the upper orange part can be seen as a simplified part of the red part, recursively solved until the N,k range ≤2333 return sm[n][k] , and the blue part of the upper formula can be solved recursively by Lucas theorem to N,k range ≤2333return C[n][k].

Code:

1#include <cstdio>2#include <cstring>3#include <algorithm>4 #defineInc (I,J,K) for (int i=j;i<=k;i++)5 #definell Long Long6 #defineMAXN 23347 #defineMoD 23338 using namespacestd;9 Ten inline ll read () { One     CharCh=getchar (); ll f=1, x=0; A      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; Ch=GetChar ();} -      while(ch>='0'&&ch<='9') x=x*Ten+ch-'0', ch=GetChar (); -     returnf*x; the } -ll N,K,C[MAXN][MAXN],SM[MAXN][MAXN];intT; - voidCalc () { -c[0][0]=sm[0][0]=1; Inc (I,1, MoD) sm[0][i]=1; +Inc (I,1, MoD) { -d[n][0]=sm[i][0]=1; +Inc (J,1, i) c[i][j]= (c[i-1][j-1]+c[i-1][J])%MoD; AInc (J,1, MoD) sm[i][j]= (sm[i][j-1]+C[I][J])%MoD; at     } - } - ll Solvec (ll n,ll k) { -     if(N<=mod&&k<=mod)returnC[N][K];Else returnSolvec (N/mod,k/mod) *c[n%mod][k%mod]%MoD; - } - ll Solvesm (ll n,ll k) { in     if(K<mod)returnSolvec (N/mod,k/mod) *sm[n%mod][k%mod]%MoD; -     return(Solvesm (n/mod,k/mod-1) *sm[n%mod][mod-1]%mod+solvec (n/mod,k/mod) *sm[n%mod][k%mod]%mod)%MoD; to } + intMain () { -t=read (); Calc (); theInc (I,1, t) {n=read (); K=read (); printf ("%lld\n", Solvesm (n,k)%mod);} *     return 0; $}

20160724

Bzoj4591[shoi2015] super-capable particle cannon/change

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.