Codeforces 474D Flowers

Posted GFY

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces 474D Flowers相关的知识,希望对你有一定的参考价值。

http://codeforces.com/problemset/problem/474/D

思路:F[i]=F[i-1]+(i>=K)F[i-k]

 1 #include<cstdio>
 2 #include<cmath>
 3 #include<algorithm>
 4 #include<cstring>
 5 #include<iostream>
 6 const int Mod=1000000007;
 7 int K,sum[200005],f[200005];
 8 int read(){
 9     int t=0,f=1;char ch=getchar();
10     while (ch<0||ch>9){if (ch==-) f=-1;ch=getchar();}
11     while (0<=ch&&ch<=9){t=t*10+ch-0;ch=getchar();}
12     return t*f;
13 }
14 void init(){
15     f[0]=1;
16     for (int i=1;i<=100000;i++){
17      f[i]=(f[i-1])%Mod;
18      if (i>=K)
19       f[i]=(f[i]+f[i-K])%Mod;
20     }
21     for (int i=1;i<=100000;i++)
22      sum[i]=(sum[i-1]+f[i])%Mod; 
23 }
24 int main(){
25     int T=read();K=read();
26     init();
27     while (T--){
28         int l=read(),r=read();
29         printf("%d\n",((sum[r]-sum[l-1])%Mod+Mod)%Mod);
30     }
31     return 0;
32 }

 

以上是关于Codeforces 474D Flowers的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces 474D Flowers

codeforces474D

Codeforces 258E Devu and Flowers

CodeForces 621CWet Shark and Flowers

codeforces 621C Wet Shark and Flowers

CodeForces 617C Watering Flowers