# Bullcow Bull and Cow (bzoj 3398)

Source: Internet
Author: User

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)

Related Keywords:

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.