Description John is going to take N (1≤n≤100000) cattle to the show at the rally, which can be bull or cow. The cows were to stand in a row. But the bull was aggressive, and John decided to have at least K (o≤k<n) cow between any two bulls in order to avoid the bull's trouble. Please calculate how many kinds of queueing methods are in common. All bulls can be seen as the same, and all cow are the same. Answer to 5000011 modulo input line, enter two integers n and k.output An integer that represents the number of methods queued. Sample Input4 2
Sample Output6
Sample Description
6 methods are: Doe DOE DOE Doe, Hart Doe Doe DOE, DOE DOE Doe, DOE Doe Hart Doe, DOE Doe Doe Hart, Hart Doe Doe HartHINT Source
Silver
/*Permutation Combinatorial problems enumerate the number of Du cattle, then remove from n the number of cow that need to be added at least, and then arrange for the du cow. Ans=σc (n-(i-1) *k,i)*/#include<cstdio>#include<iostream>#defineMoD 5000011#defineLon Long Longusing namespacestd;intN,k;lon Ans;lon ksm (lon A,lon b) {lonBase=a,r=1; while(b) {if(b&1) r*=Base; Base*=Base; R%=MoD; Base%=MoD; b>>=1; } returnR;} Lon C (intNintm) {m=min (m,n-m); Lon r1=1, r2=1; for(inti=n-m+1; i<=n;i++) r1= (r1* (lon) i)%MoD; for(intI=1; i<=m;i++) r2= (r2*i)%MoD; return(R1*ksm (r2,mod-2))%MoD;}intMain () {scanf ("%d%d",&n,&k); for(intI=0; i<=n;i++){ intt=n-(I-1)*K; if(T<i) Break; Ans= (Ans+c (t,i))%MoD; } cout<<ans; return 0;}
Bullcow Bull and Cow (bzoj 3398)