Combination count bull and heifers ------

John to take NN oxen to attend the rally in the exhibition, these cattle can be a bull, a cow can be.
Cattle have to stand in a row, but the bull is aggressive, in order to avoid bull trouble go wrong, John decided to have at least KK only heifers between any two bull.
Calculate the number of ways a total of queuing, all bull can be seen as the same, all the same cow, the answer to the modulo 50,000,115,000,011.
Input format
line, and input two integers NN KK.
Output format
number an integer representing the queuing method.
Data range
1≤N≤1051≤N≤105,

0≤K <N0≤K <N
input samples:
42

Sample output:
6

Sample interpretation
66 kinds of methods are: female female female female, male female female female, female male female female, female female male female, female female male female, male female male female.

Thinking: f [n] is represented by n the number of possible species for all the last 1, and recursive, with all the possible positions of the penultimate 1

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 100010, mod = 5000011;
int n, k;
int f[N], s[N];
int main(){
 cin >> n >> k;
  s[0] = f[0] = 1;
 for (int i = 1; i <= n; i ++){
  f[i] = s[max(i - k - 1, 0)];
  s[i] = (s[i - 1] + f[i]) % mod;
 }
  cout << s[n] << endl;
  return 0;
}
Published 106 original articles · won praise 67 · views 5407

Guess you like

Origin blog.csdn.net/qq_45772483/article/details/105061354