bzoj 3398
f[i]表示最后一个是公牛的方案数,=sigma(f[j])(j<i-k) 然后前缀和优化即可。
#include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <cmath> #define Mod 5000011 using namespace std; const int N = 1e5 + 10; int f[N], sum[N]; int main() { int n, K; scanf("%d%d", &n, &K); K ++; f[0] = sum[0] = 1; for(int i = 1; i <= n; i ++) { int j = i - K; if(j < 0) f[i] = 1; else f[i] = sum[j]; sum[i] = (f[i] + sum[i - 1]) % Mod; } printf("%d", sum[n]); return 0; }