题目
分析
- 递推
- 当1-k f[i]=i+1;
- >k f[i]=f[i-1]+f[i-k-1]
代码
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 }