JZOJ 1292. bulls and cows

topic

Description

  N FJ like cattle (cow or bull) receiving a row of Hu review, the study found particularly aggressive bulls, bulls if the two are too close from the conflict will, by observing the two have at least between bull K (0 <= K <= N) cows in order to avoid conflicts.
  FJ would like you to help calculate a total number of species placement method, note that all the bulls are considered the same, the cow is so placed in two positions methods are considered different if and only if certain positions of different types of cattle.
 

Input

  The first line: two spaces separated by an integer N (N <= 100000) and K.

Output

  An integer that represents the total output method, the answer may be large, so just output mod 5,000,011 in value.
 

Sample Input

4 2

Sample Output

6
 

Data Constraint

 
 

Hint

[] Sample shows
the following six kinds of placement method, 'B' represents a bull, 'C' denotes the cow
CCCC
BCCC
CBCC
the CCBC
the CCCB
BCCB

 

analysis

 

  • Recurrence
  • Those 1-kf [i] = i + 1;
  • >k f[i]=f[i-1]+f[i-k-1]

 

Code

 1 #include <cmath>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <iostream>
 5 #include <algorithm>
 6 const int MOD = 5000011;
 7 using namespace std; 
 8 int f[100001];
 9 int main(){
10     int n,k;
11     scanf("%d%d",&n,&k);
12     for (int i=0;i<=n;i++)
13     {
14         if (i<=k) f[i]=i+1;
15         else f[i]=(f[i-1]+f[i-k-1])%MOD;
16     }
17     cout<<f[n];
18     return 0;
19 }

 

 

 

Guess you like

Origin www.cnblogs.com/zjzjzj/p/11773707.html